Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Re: Validate fields

Quote Reply
Re: Validate fields In reply to
Some tips on regexp's:

^ - match at beginning.
$ - match at end.
\d - match any number 0 to 9.
\w - match any letter A - Z, lowercase a -z, any numbers 0-9 as well as the underscore _.
\s - match whitespace, normally only tab and spaces.
[] - character class, match anything inside the brackets.
* - match 0 or more occurrences.
+ - match 1 or more occurrences.
? - match 0 or 1 occurence.

From that list, you say you want to allow letters, numbers or spaces, but nothing weird like ^{& etc. You could then use:

^[\w\s]+$

if you wanted at least something to be filled in (note the plus for one or more).

or

^[\w\s]*$

if the field can be left blank (note the star meaning zero or more). Be sure to explain to your users what you are seeking, because this will cough up an error if they try to use any punctuation like apostrophe's, etc.

Also, note: accents are considered different in perl!! So a é is not the same as a e. If you want to allow accents, you have to put those into the character class like:

^[\w\dé]*$

Hope that helps,

Alex
Subject Author Views Date
Thread Validate fields Robert 3750 Jan 15, 2000, 4:28 AM
Post Re: Validate fields
pugdog 3609 Jan 15, 2000, 4:43 AM
Post Re: Validate fields
widgetz 3608 Jan 15, 2000, 1:09 PM
Post Re: Validate fields
pugdog 3606 Jan 15, 2000, 1:44 PM
Post Re: Validate fields
Robert 3605 Jan 16, 2000, 5:14 AM
Post Re: Validate fields
pugdog 3605 Jan 16, 2000, 5:58 AM
Post Re: Validate fields
Robert 3606 Jan 16, 2000, 7:57 AM
Post Re: Validate fields
Alex404 3599 Jan 16, 2000, 8:47 AM
Post Re: Validate fields
Robert 3610 Jan 16, 2000, 11:36 AM
Post Re: Validate fields
pugdog 3604 Jan 16, 2000, 5:55 PM
Post Re: Validate fields
Alex 3607 Jan 17, 2000, 8:37 AM