Skip to content Skip to sidebar Skip to footer

Regular Expression For Lastname, Firstname With Space

I am using the below JS to enter name in LastName, FirstName format like this Clark, Michael and now I also probably need to allow names like this Tim Duncan, Vince Carter where th

Solution 1:

^[\w ]{1,20}\, [\w ]{1,20}$

This should work for you.

Solution 2:

Maybe this will meet your expectations.

/^\s*(\w{1,20} *[^,]*)+,\s+(\w{1,20}\s*)+$/

However above regex will accept also multiple white spaces before and after name. If you want to force only one space character format you should use these regex:

/^(\w{1,20} ?[^,]*)+, (\w{1,20}( [^$]|$))+$/

Solution 3:

You can use html5 pattern..

<inputtype="text"title="Following format: FirstName LastName"pattern="^\s*([\w]{1,20}( |,)?)+\s*,\s+([\w]{1,20} *)+$" />

Post a Comment for "Regular Expression For Lastname, Firstname With Space"