JRS: In article <fS******************@newsfe2-gui.ntli.net>, dated Wed,
28 Jun 2006 17:19:07 remote, seen in news:comp.lang.javascript, Advo
<x@x.com> posted :
At the moment my code is like:
function telValid(inString) {
var regexp = /^[0-9 \+\(\)]+$/;
return (inString.match(regexp,''));
}
which is use to validate phone numbers (UK at the moment)
this works ok, but wont allow - (Dashes) which i need..
It will allow ')(' as a number, also ' '.
There's no point in validating at all unless you can do a better job
than just ensuring no invalid characters and at least one character.
First, list the allowable formats. You seem to want to allow +44;
should the "STD" part, (0)20 for London, be optional?
BTW, the numbers of phones within the UK are not necessarily UK phone
numbers (the inverse Ley effect); there are foreigners among us.
You should end up with something more like
function telValid(inString) {
return /^(\(\+\d{1,3}\))?\d{8,11}$/.test(inString.replace(/[- ]/g, "")) }
which accepts (+474) 077 667778
but that's probably too short and the parentheses are probably
mis-placed.
--
© 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.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.