Javascript Regex Replace string, special character need help
Posted
by
Mohummad Abdullah
on Stack Overflow
See other posts from Stack Overflow
or by Mohummad Abdullah
Published on 2011-06-20T09:09:22Z
Indexed on
2011/06/20
16:22 UTC
Read the original article
Hit count: 172
JavaScript
|replace
I am trying to replace string on page in runtime
example: find string "(800).123.4567"
to "<span>(800)123.4567</span>"
means i want to add span tag before and after of string. here is i m doing this is my code:
var avidno = '(800)123 1234';
function validate () {
var regex = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
if (regex.test(avidno)) {
alert('bingo');
var altrstr = '<span>'+avidno+'</span>';
alert(altrstr);
// Valid international phone number
} else {
alert('uupss');
// Invalid international phone number
}
}
validate();
© Stack Overflow or respective owner