Regular expression to validate and formate text strings. PATTERNS/OPERATORS/SYMBOLS =============================================== Regular expressions / Special characters : =============================================== / (slash) : always begins and ends a regular expression. \ : toggle between literal and special characters. ^ (caret) : beginning of the string. $ : end of the string. ( ) (parenthesis) : reference to a group. * zero or more time ? zero or one time + one or more time ------------------------------------------------------ \b : word boundary. \B : non-word boundary. \d : digits (0->9). \D : any non-digits. \f : form feed. \n : new line. \. : any character except new line. \r : carriage return. \s : any white space character. \S : any non-white space character. \t : tabulation. \v : vertical tabulation. \w : any character (letter, number, underscore). \W : any character other than a letter, a number, an underscore. \xnn : the ASCII character defined by the hexadecimal nn. \onn : the ASCII character defined by the octal nn. \cX : the control character X. ------------------------------------------------------ {x} : x occurences of the previous character. {x,} : at least x occurences of the previous character. {x,y} : between x and y occurences of the previous character. {x|y} : x or y occurences of the previous character. ------------------------------------------------------ [ xyz] (bracket) : enclosed characters are allowed; [^xyz ] : enclosed characters are not allowed; [ a-k] : any character in this range is allowed; =============================================== Regular expression Modifier : (set after the final slash) =============================================== g : search globally for all possible matches. i : search without case sensitive (lowercase/uppercase). =============================================== Regular expressions : (samples...) =============================================== E-mail address : /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ ex : gilles.saunier@free.fr ------------------------------------------------------ URL : data = /^(file|http):\/\/\S+\/\S+$/i ex : http://gilles.saunier.free.fr ------------------------------------------------------ Filename URL : data = /^(file|http):\/\/\S+\/\S+\.(gif|jpeg|jpg)$/i ex : http://gilles.saunier.free.fr/gif/pix.gif ------------------------------------------------------ Phone number : data = /^\(?(\d{2})\)?[- ]?(\d{4})[- ]?(\d{4})$/ ex : (02) 9863 2884 02-9863-2884 0298632884... ------------------------------------------------------ Date : data = /^(\d{2})[/](\d{2})[/](\d{4})$/ ex : 08/25/2004 ------------------------------------------------------ Time : data = /^(\d{2})[:](\d{2})[:](\d{2})$/ ex : 04:12:56