CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Regular expression validation

 



Palpatine43
New User

May 18, 2013, 4:08 PM

Post #1 of 6 (11952 views)
Regular expression validation Can't Post

I am trying to learn some regular expressions to validate different inputs. Can someone help me out with these?

Provide a perl regular expression that can be used to validate each of the following pattern descriptions:
• a 3 digit area code
• a 3 digit area code that must be enclosed in parenthesis
• a 3 digit area code that may be enclosed in parenthesis
• a 9 digit social security number
• a 9 digit social security number that must include dashes after the 3rd and 5th digit
• a 9 digit social security number that might include dashes after the 3rd and 5th digit

Thank you!


Laurent_R
Veteran / Moderator

May 19, 2013, 7:52 AM

Post #2 of 6 (11940 views)
Re: [Palpatine43] Regular expression validation [In reply to] Can't Post

I do not know if there is anything special about area codes, but a 3-digit code could be:


Code
/\d{3}/ or /\d\d\d/ or /[0-9]{3}/


The first one is the simplest, but I wanted to show that there are other ways to do the same (TIMTOWTDI).

3-digit code enclosed in parens:


Code
 /\(\d{3}\)/


With optional parens:


Code
 /\(?\d{3}\)?/


For sosical security numbers, I don't now how they look like in your country.


Kenosis
User

May 19, 2013, 11:13 PM

Post #3 of 6 (11927 views)
Re: [Palpatine43] Regular expression validation [In reply to] Can't Post

Is this an end-of-the-semester exam?


(This post was edited by Kenosis on May 19, 2013, 11:13 PM)


BillKSmith
Veteran

May 20, 2013, 10:45 AM

Post #4 of 6 (11910 views)
Re: [Laurent_R] Regular expression validation [In reply to] Can't Post


I do not know if there is anything special about area codes,...

Quote

This is exactly the reason for preferring a module. Someone else is responsible for these details (and keeping them up-to-date.)
Good Luck,
Bill


hwnd
User

May 20, 2013, 2:28 PM

Post #5 of 6 (11903 views)
Re: [BillKSmith] Regular expression validation [In reply to] Can't Post

I already answered you on your cross post here. http://perlguru.com/gforum.cgi?post=74894;sb=post_latest_reply;so=ASC;forum_view=forum_view_collapsed;session=7398f6a0f2a7cf0f211bd60c2019a5a1;page=unread#unread


Laurent_R
Veteran / Moderator

May 20, 2013, 3:05 PM

Post #6 of 6 (11900 views)
Re: [BillKSmith] Regular expression validation [In reply to] Can't Post


In Reply To

I do not know if there is anything special about area codes,...

Quote

This is exactly the reason for preferring a module. Someone else is responsible for these details (and keeping them up-to-date.)


Yeah, true in general, except that the world is vast and that the module you are talking about is only for US areas code, and the OP has not specified if he or she was talking about US area codes or those from another country

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives