Share phone numbers for sex chat

You'll have a hard time dealing with international numbers with a single/simple regex, see this post on the difficulties of international (and even north american) phone numbers.

In my opinion, the most elegant solution is to validate a minimum length, nothing more.

How are extensions (e.g., 111-222-3333 x 44444) going to be handled? Even if you could write a big, hairy validator that would allow all the different legitimate formats, it would end up allowing pretty much anything even remotely resembling a phone number in the first place.

Share phone numbers for sex chat-24Share phone numbers for sex chat-62Share phone numbers for sex chat-24

It turns out that there's something of a spec for this, at least for North America, called the NANP. Beyond that - the list you gave does not include another common US format - leaving off the initial 1.

You'll want to parse the first few digits to determine what the country code is, then act differently based on the country.

:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(? When you match, $1 contains the area code, $2 and $3 contain the phone number, and $5 contains the extension. Do you foresee any need to allow square, curly, or angled brackets for some regions? If you want to maintain per digit rules (such as in US Area Codes and Prefixes (exchange codes) must fall in the range of 200-999) well, good luck to you.

I came up with this: Here's a perl script to test it. It should be compatible with international numbers and localization formats.

That's so that the phone company can calculate when you are done dialing. But your regex doesn't check the area code portion, so that doesn't seem to be a concern.

Like validating email addresses, even if you have a valid result you can't know if it's assigned to someone until you try it.Most cell phones in the US don't require it, and it'll start to baffle the younger generation unless they've dialed internationally.You've correctly identified that it's a tricky problem...For further analysis you can subscribe to one of many providers that will give you access to a database of valid numbers as well as tell you if they're landlines or mobiles, disconnected, etc. You would probably be better off using a Masked Input for this.That way users can ONLY enter numbers and you can format however you see fit.I'm not the original author, but I think it's well worth sharing as I found this problem to be very complex and without a concise or widely useful answer.

Tags: , ,