By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,165 Members | 853 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,165 IT Pros & Developers. It's quick & easy.

help for regular expression

P: n/a
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
Jan 24 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
gr********@googlemail.com wrote:
I can't figure out what the regular expression would look like for
validating a string such as :

Lastname, Firstname
/\w+, \w+/

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 24 '08 #2

P: n/a
On 24 Jan, 17:31, Martin Honnen <mahotr...@yahoo.dewrote:
graphic...@googlemail.com wrote:
I can't figure out what the regular expression would look like for
validating a string such as :
Lastname, Firstname

* */\w+, \w+/

--

* * * * Martin Honnen
* * * *http://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.

Thanks
Jan 24 '08 #3

P: n/a
Lee
gr********@googlemail.com said:
>
On 24 Jan, 17:31, Martin Honnen <mahotr...@yahoo.dewrote:
>graphic...@googlemail.com wrote:
I can't figure out what the regular expression would look like for
validating a string such as :
Lastname, Firstname

=A0 =A0/\w+, \w+/

--

=A0 =A0 =A0 =A0 Martin Honnen
=A0 =A0 =A0 =A0http://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? 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.
--

Jan 24 '08 #4

P: n/a
gr********@googlemail.com wrote:
On 24 Jan, 17:31, Martin Honnen <mahotr...@yahoo.dewrote:
>graphic...@googlemail.com wrote:
>>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...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
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jan 24 '08 #5

P: n/a
On Jan 24, 1:20*pm, Lee <REM0VElbspamt...@cox.netwrote:
graphic...@googlemail.com said:


On 24 Jan, 17:31, Martin Honnen <mahotr...@yahoo.dewrote:
graphic...@googlemail.com wrote:
I can't figure out what the regular expression would look like for
validating a string such as :
Lastname, Firstname
=A0 =A0/\w+, \w+/
--
=A0 =A0 =A0 =A0 Martin Honnen
=A0 =A0 =A0 =A0http://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? *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
Jan 24 '08 #6

P: n/a
Lee
nolo contendere said:
>
On Jan 24, 1:20=A0pm, Lee <REM0VElbspamt...@cox.netwrote:
>graphic...@googlemail.com said:


>On 24 Jan, 17:31, Martin Honnen <mahotr...@yahoo.dewrote:
graphic...@googlemail.com 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.
--

Jan 24 '08 #7

P: n/a
In comp.lang.javascript message <c5dc03c1-54c7-410d-8d07-aa88b8d6dac6@n2
0g2000hsh.googlegroups.com>, Thu, 24 Jan 2008 09:16:16,
gr********@googlemail.com 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
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)
Jan 24 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.