473,396 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

regular expression question

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

Aug 14 '06 #1
10 1589
Rik
sa*************@googlemail.com wrote:
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
Basically:
^([a-z]+,\s*){2}[a-z0-9]+$/i

Problem here is exotic characters like ç, ö, etc, which are offcourse
totally valid in names, but won't match here. Also spaces (\s), -, ' etc....

Grtz,
--
Rik Wasmus
Aug 14 '06 #2
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.

Aug 14 '06 #3
Rik
sa*************@googlemail.com wrote:
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.
^([a-z\s]+,){2}[a-z0-9\s]+$/i
Grtz,
--
Rik Wasmus
Aug 14 '06 #4
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
?

Aug 14 '06 #5
Please ignore my last post.

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

Aug 14 '06 #6
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.

Aug 14 '06 #7
Rik
sa*************@googlemail.com wrote:
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.

Tsssk, get your requirements straight :-).

Here you go:
^(\s*([a-z]+\s*)+,){2}\s*([a-z0-9]+\s*)+$/i

Grtz,
--
Rik Wasmus
Aug 14 '06 #8
JRS: In article <11**********************@75g2000cwc.googlegroups. com>,
dated Mon, 14 Aug 2006 06:19:25 remote, seen in
news:comp.lang.javascript, sa*************@googlemail.com 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>

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 14 '06 #9
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

Aug 15 '06 #10
Rik
sa*************@googlemail.com wrote:
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
^(\s*([a-z]+\s*)+,){2}\s*([a-z0-9]+.*)+$/i

Grtz,
--
Rik Wasmus
Aug 15 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Vibha Tripathi | last post by:
Hi Folks, I put a Regular Expression question on this list a couple days ago. I would like to rephrase my question as below: In the Python re.sub(regex, replacement, subject)...
5
by: Bradley Plett | last post by:
I'm hopeless at regular expressions (I just don't use them often enough to gain/maintain knowledge), but I need one now and am looking for help. I need to parse through a document to find a URL,...
10
by: Lee Kuhn | last post by:
I am trying the create a regular expression that will essentially match characters in the middle of a fixed-length string. The string may be any characters, but will always be the same length. In...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
5
by: Ryan | last post by:
HELLO I am using the following MICROSOFT SUGGESTED (somewhere on msdn) regular expression to validate email addresses however I understand that the RFP allows for "+" symbols in the email address...
7
by: norton | last post by:
Hello, Does any one know how to extact the following text into 4 different groups(namely Date, Artist, Album and Quality)? - Artist - Album Artist - Album - Artist - Album - Artist -...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
3
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.