View Full Version : simple regex matching help

03-11-2010, 12:06 AM
Hi, I'm trying to match valid names from a list. Valid names can only contain letters, periods ".", commas "," , spaces " ", and must atleast contain 1 letter.

var checkname = /[a-zA-Z]+(\.|,|\s)*/;

but with this regex string, it also matches names that contain letters and numbers. How do I make it to match only what I've mentioned above?
Any help would be appreciated...


03-11-2010, 03:48 AM

I'm guessing by the example you gave that you also want the name to be valid only when it starts with a letter. Here's one way to go about it:

var checkname = /^[a-zA-Z][a-zA-Z., ]*$/;

This is assuming that the beginning and ending white-space has already been stripped from the variable you're checking against.

- C. Aaron Smith

03-11-2010, 05:08 AM
Thanks, I completely forgot about the start and end anchors..

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum