Page 1 of 1

regexp - form validation

Posted: Sat Aug 30, 2014 12:12 am
by donny
hello

i am using the bootstrap form validator for bootstrap.

i am having trouble understanding regexp

regexp: /^[a-z\s]+$/i,

this code will only allow the field to consist of alphabetical characters and spaces only.

can somebody break down each thing in there for me and separate what is what so i can learn how to change the variations and put new ones together. i tried googling regexp javascript and there is some information but its still also very confusing.

i am new to javascript.

thank you

Re: regexp - form validation

Posted: Sat Aug 30, 2014 7:39 am
by Celauran
This isn't even a Javascript question, but a regex one.

For the regular expression

Code: Select all

/^[a-z\s]+$/i
/ is the pattern delimiter
^ denotes the beginning of a line, in the case of forms it would be the beginning of the value
[] denotes a range of characters. Anything within that range will be accepted.
a-z is just that, the letters a through z
\s indicates a space
+ indicates 1 or more occurrences
$ denotes the end of the line
i at the end means case insensitive.

Re: regexp - form validation

Posted: Sat Aug 30, 2014 7:39 am
by Celauran
Debuggex and Rubular might be helpful here, also.