help for regular expression

G

graphicsxp

Hi,

I can't figure out what the regular expression would look like for
validating a string such as :

Lastname, Firstname

I could only come up with /\w/ which doesn't check for the comma.

Can someone help ?

Thanks
 
G

graphicsxp

   /\w+, \w+/

Thanks for the help ! Actually it's not exactly what I need as this
would only check for the coma and other characters around the coma.
The expression needs to check for litterals only and one comma only.

Thanks
 
L

Lee

(e-mail address removed) said:
Thanks for the help ! Actually it's not exactly what I need as this
would only check for the coma and other characters around the coma.
The expression needs to check for litterals only and one comma only.

Martin's regular expression checks for more than zero alphabetic or
numeric characters, followed by a single comma then a single space,
followed by more than zero alphabetic or numeric characters.

What do you believe "literal" means? If you want alphabetic
characters only , the expression would be:

/[a-z]+,\s*[a-z]+/i

This also allows zero or more spaces or tabs (or other whitespace)
after the comma.


--
 
T

Thomas 'PointedEars' Lahn

I can't figure out what the regular expression would look like for
validating a string such as : Lastname, Firstname
/\w+, \w+/

[signature]

[...] Actually it's not exactly what I need

Tough luck. Use Brain 1.0:

http://jibbering.com/faq/
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:RegExp
as this would only check for the coma and other characters around the
coma. The expression needs to check for litterals only and one comma
only.

Once you get out of your coma, you may be able to post an understandable
message.


PointedEars
 
D

Dr J R Stockton

In comp.lang.javascript message <c5dc03c1-54c7-410d-8d07-aa88b8d6dac6@n2
0g2000hsh.googlegroups.com>, Thu, 24 Jan 2008 09:16:16,
(e-mail address removed) posted:
I can't figure out what the regular expression would look like for
validating a string such as :

Lastname, Firstname

A correct solution will allow for people whose family (or other) name
contains non-alphabetic characters.

Consider :
Jean-Jacques Rousseau
Patrick O'Brian
Sir Ian Moncrieffe of that Ilk
François Mitterand
 
N

nolo contendere

(e-mail address removed) said:




Thanks for the help ! Actually it's not exactly what I need as this
would only check for the coma and other characters around the coma.
The expression needs to check for litterals only and one comma only.

Martin's regular expression checks for more than zero alphabetic or
numeric characters, followed by a single comma then a single space,
followed by more than zero alphabetic or numeric characters.

What do you believe "literal" means?  If you want alphabetic
characters only , the expression would be:

/[a-z]+,\s*[a-z]+/i

This also allows zero or more spaces or tabs (or other whitespace)
after the comma.

better make that: /^[a-z]+,\s*[a-z]+$/i
 
L

Lee

nolo contendere said:
(e-mail address removed) said:




(e-mail address removed) wrote:
I can't figure out what the regular expression would look like for
validating a string such as :
Lastname, Firstname
=3DA0 =3DA0/\w+, \w+/

=3DA0 =3DA0 =3DA0 =3DA0 Martin Honnen
=3DA0 =3DA0 =3DA0 =3DA0http://JavaScript.FAQTs.com/
Thanks for the help ! Actually it's not exactly what I need as this
would only check for the coma and other characters around the coma.
The expression needs to check for litterals only and one comma only.

Martin's regular expression checks for more than zero alphabetic or
numeric characters, followed by a single comma then a single space,
followed by more than zero alphabetic or numeric characters.

What do you believe "literal" means? =A0If you want alphabetic
characters only , the expression would be:

/[a-z]+,\s*[a-z]+/i

This also allows zero or more spaces or tabs (or other whitespace)
after the comma.

better make that: /^[a-z]+,\s*[a-z]+$/i

Yes. I was sure I had anchored it, but apparently not.


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top