KavyaVS
asked on
Regular expression for Business Phone number
I am using this regular expression for business phone number
"^\(?([2-9][0-8][0-9](?<!1 1))\)?([2- 9][0-9]{2} )?([0-9]{4 })([0-9]{0 ,4})$".
But this is accepting '1' in the 4th place (The first digit in exchange code).But it should allow only 2-9 in the 4th place.
Please let me know the mistake in it.
Thanks,
Rama
"^\(?([2-9][0-8][0-9](?<!1
But this is accepting '1' in the 4th place (The first digit in exchange code).But it should allow only 2-9 in the 4th place.
Please let me know the mistake in it.
Thanks,
Rama
"^\(?([2-9][0-8][2-9](?<!1 1))\)?([2- 9][0-9]{2} )?([0-9]{4 })([0-9]{0 ,4})$".
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks Kaufmed. It is working now.I deleted that question mark after exchange code and now it is not accepting 1 as the first digit in the exchange code.
You gave me the regular expressions for Home Phone and Business Phone number.
Home Phone:"^\(?([2-9][0-8][0-9 ](?<!11))\ )?([2-9][0 -9]{2})?([ 0-9]{4})$"
Business Phone:"^\(?([2-9][0-8][0-9 ](?<!11))\ )?([2-9][0 -9]{2})([0 -9]{4})([0 -9]{0,4})$ "
So the Home Phone expression also have mistake in it.
Thanks.
You gave me the regular expressions for Home Phone and Business Phone number.
Home Phone:"^\(?([2-9][0-8][0-9
Business Phone:"^\(?([2-9][0-8][0-9
So the Home Phone expression also have mistake in it.
Thanks.
You gave me the regular expressions for Home Phone and Business Phone number.I remember : )
So the Home Phone expression also have mistake in it.Same issue. You have a question mark after exchange.
ASKER
I deleted the question mark after exchange code in Home Phone regular expression.
It has question mark after area code also. Is it O.k
I am using the following regular expression for street Address
\d{1,3}.?\d{0,3}\s[a-zA-Z] {2,30}(\s[ a-zA-Z]{2, 15})?([#\. 0-9a-zA-Z] *)?
Can you suggest me any corrections to accept all kind of street addresses.
Thanks
It has question mark after area code also. Is it O.k
I am using the following regular expression for street Address
\d{1,3}.?\d{0,3}\s[a-zA-Z]
Can you suggest me any corrections to accept all kind of street addresses.
Thanks
Can you suggest me any corrections to accept all kind of street addresses.
I'm afraid I cannot because I am not familiar with all the different accepted possibilities. I know common ones such as those for houses or apartments, but I don't know all the characters that would be involved. You may consider looking into some address normalization product.
ASKER
I know common ones such as those for houses or apartments.
Please give it me whatever you know.You mentioned that you know common ones such as those for
houses or apartments.I want to try that one.
Thanks.
Please give it me whatever you know.You mentioned that you know common ones such as those for
houses or apartments.I want to try that one.
Thanks.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Actually, I forgot to make "street name" allow multiple words. Use this instead:
\d+\s+[\w\s-]+\s+[a-zA-Z]{2,}\.?(?:\s+[a-zA-Z]{2,3})?(?:\s+[a-zA-Z]+\.?\s+\d*)?
// Breakdown
\d+ Bldg Number
\s+ At least a space
[\w\s-]+ Street Name
\s+ At least a space
[a-zA-Z]{2,} Street Designator (e.g. AVE, ST, RD, etc.)
\.? Optional dot (some people abbreviate with dot)
// Optional ( ? )
\s+ At least a space
[a-zA-Z]{2,3} Direction Indicator (e.g. NW, SW, etc.); This might need tweaking
// Optional ( ? )
\s+ At least a space
[a-zA-Z]+ Secondary Designator (e.g. STE, APT, etc)
\.? Optional dot (some people abbreviate with dot)
\s+ At least a space
\d* Secondary Designator Number (e.g. 12, as in APT 12; not all secondary designators have numbers, so digits is optional [ * ])
ASKER
Thanks for your detailed explanation and time.
783,Frederick Stamm Ct.,Apt#2 is not working.
783,Frederick Stamm Ct.,Apt#2 is not working.
Ok. So we need to add commas and hashes ( # ). Let's see if this functions better:
\d+(?:\s*,)?[\w\s-]+\s+[a-zA-Z]{2,}\.?(?:\s+[a-zA-Z]{2,3})?,?(?:\s*[a-zA-Z]+\.?\s*#?\s*\d*)?
ASKER
Thanks.It's working now.
ASKER
Thank you very much.