...

View Full Version : RegExp phone number help



johnish
08-17-2008, 07:43 AM
hey guys, using regxp
and i have a phone number form which needs to have +33 0 at the start and then 5 numbers

i have this so far

(/^\+33\s 0(\d{5}$)/);

can someone help?

oesxyl
08-17-2008, 07:57 AM
hey guys, using regxp
and i have a phone number form which needs to have +33 0 at the start and then 5 numbers

i have this so far

(/^\+33\s 0(\d{5}$)/);

can someone help?
see this doc about phone numbers:

http://www.itu.int/rec/T-REC-E.123/en

I use this with onblur, to reformat the phone number. The val value is the string from input, you can get it for example with document.getElementById('phid').value or something similar. With returned value must fill the input.


function phone_normalize_e123(val){
var pn = (val ? (val.replace(/[^\(\)\+\d]/g,'')) : '');
if(/^\+/.test(pn)){
return pn.replace(/[\+\(\)]/g,'').replace(/^(\d{2})(\d{2})(\d{3})(\d{4})$/,"+$1 $2 $3 $4");
}
if(/^\(/.test(pn)){
return pn.replace(/[\+\(\)]/g,'').replace(/^(\d{3})(\d{3})(\d{4})$/,"($1) $2 $3");
}
return pn;
}


this validate val to be valid formated. Same explanation about val, it return true or false.


function check_phone_e123(val){
return (val ? (/^\(\d{3}\)\s\d{3}\s\d{4}$/.test(val) ||
/^\+\d{2}\s\d{2}\s\d{3}\s\d{4}$/.test(val)) : false);
}


work only toghater, that to make the check_phone_e123 regex simpler.

best regards

Philip M
08-17-2008, 09:14 AM
hey guys, using regxp
and i have a phone number form which needs to have +33 0 at the start and then 5 numbers

i have this so far

(/^\+33\s 0(\d{5}$)/);

can someone help?

What was wrong with your regex was the space befoe the 0. Should be:-


if(/(^\+33\s0\d{5}$)/.test(lstr.value)) {



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum