Reputation: 2556
How to write a regular expression to take +Z (YYY) XXX-XX-XX
, and get YYYXXXXXXX
? This is for phone number.
Upvotes: 1
Views: 151
Reputation: 4906
if you have exact the format +Z (YYY) XXX-XX-XX
:
var num = input.replace( '/^\+\S+\s\((\d{3})\)\s(\d{3})-(\d{2})-(\d{2})$/', '\1\2\3\4' );
but a more tolerant variant would be
var num = input.replace( '/^(\+\S+|\D/', '' );
Upvotes: 0
Reputation: 57342
you can do this by
var mobile = "+Z (567) 567-567-567";
var n=mobile.replace("(","");
n =n.replace(/[^0-9]+/g, '');
alert(n)
Upvotes: 1