doug007 Posted June 17, 2009 Share Posted June 17, 2009 Hi Guys, I am trying to write a regex that will allow a number of any length and can contain spaces or plus sign or brackets like so, but it should not accept any letter (a-z): 0207 7895 478 02077895478 +44(0)207 7895 478 thanks Link to comment https://forums.phpfreaks.com/topic/162645-regex-phone-number/ Share on other sites More sharing options...
thebadbad Posted June 17, 2009 Share Posted June 17, 2009 ~^[0-9 +()]*$~D Remember that it also will match an empty string, or something odd like +() ++)++( +( (( Link to comment https://forums.phpfreaks.com/topic/162645-regex-phone-number/#findComment-858429 Share on other sites More sharing options...
nrg_alpha Posted June 17, 2009 Share Posted June 17, 2009 So assuming this is a form field for a phone number, I would simply have the user enter the area code and number, but allow them to format it the way they are comfortable with and simply strip out all non-numerical characters and use what you have left. This short one page long thread touches base on this issue. Link to comment https://forums.phpfreaks.com/topic/162645-regex-phone-number/#findComment-858462 Share on other sites More sharing options...
thebadbad Posted June 18, 2009 Share Posted June 18, 2009 So assuming this is a form field for a phone number, I would simply have the user enter the area code and number, but allow them to format it the way they are comfortable with and simply strip out all non-numerical characters and use what you have left. This short one page long thread touches base on this issue. That is actually a nice way of doing it. Link to comment https://forums.phpfreaks.com/topic/162645-regex-phone-number/#findComment-858726 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.