regexp - form validation

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

regexp - form validation

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: regexp - form validation

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: regexp - form validation

Post by Celauran »

Debuggex and Rubular might be helpful here, also.
Post Reply