regular expression question

S

samuelberthelot

Hi,
I'd like to use regular expression for checking validity of a field.
What would be the expression for :

firstname, lastname, organisation23

so basically, a string + comma then another string + comma then a
alphanumeric string


thanks
 
S

samuelberthelot

Thanks Rik,

I don't need to handle those special characters anyway ... lucky me.
however i do need to handle spaces ! I mean spaces should be allowed.
 
S

samuelberthelot

Thanks,

I've tried to use it this way :

/^([a-z\s]+,){2}[a-z0-9\s]+$/i.exec(myString)

but whatever the value of myString is, it always return null. Any clue
?
 
S

samuelberthelot

Please ignore my last post.

Your regex, works just great !
thank you very much.
 
S

samuelberthelot

After a few tests I can say it works almost well.
The only thing is that it allows me to enter something like
test, ,test

so basically, spaces should be allowed BUT there should be at least one
character, in other words empty strings should not be allowed.
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Mon, 14 Aug 2006 06:19:25 remote, seen in
news:comp.lang.javascript, (e-mail address removed) posted :
I'd like to use regular expression for checking validity of a field.
What would be the expression for :

firstname, lastname, organisation23

so basically, a string + comma then another string + comma then a
alphanumeric string

Maybe no : better a commaless string + comma then another commaless
string + comma then a string; and ignoring whitespace between elements
if you use, say, .match to get the three elements.

Only of it is impossible for the organisation name to contain a comma
(or other non-alphanumeric) would your description serve,

Consider the case of

St = "James, Smith, Mart-Wal & sons, Inc."
M = St.match(/^([^,]+),\s*([^,]+),\s*(.+$)/)

No match : M = null
Match : M[1]..M[3] are the fields.

<URL:http://www.merlyn.demon.co.uk/js-valid.htm>
 
S

samuelberthelot

John,
Your comment is very relevant. I had not thought of that :(
How could I valid non-alphanumeric characters in the third string ?

Thank you
 

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,710
Latest member
bernietqt

Latest Threads

Top