0

There is the following code:

$("#ce_clientphone").inputmask("+9(999)9999999")
...
console.log($('#ce_clientphone').unmask())

As you can see I try to get value from '#ce_clientphone' without brackets. How can I do it? I need to allow user to input valid phone, but to save it in the database I need to remove brackets. Thanks in advance.

malcoauri
  • 11,904
  • 28
  • 82
  • 137
  • 1
    $(selector).inputmask('unmaskedvalue'); https://github.com/RobinHerbots/jquery.inputmask#unmaskedvalue – GLlompart Sep 08 '14 at 10:11
  • possible duplicate of [javascript Regex get string inside brackets,removing brackets](http://stackoverflow.com/questions/18559762/javascript-regex-get-string-inside-brackets-removing-brackets) – Aditya Singh Sep 08 '14 at 10:25

3 Answers3

0

You could do regular expressions and replace to remove the brackets

"+9(999)9999999".replace(/[()]/g,'');
Joseph
  • 117,725
  • 30
  • 181
  • 234
0

Try this:

$('#ce_clientphone').unmask().replace(/[()]/g, '');

For example:

"+9(999)9999999".replace(/[()]/g, '');

Returns:

"+99999999999"

So, how does this work?

We're using a regex to replace the brackets:

/  // Start of regex
[  // Start of character group
() // match either of these characters in the group (So match `(` OR `)`)
]  // End of character group
/  // End of regex
g  // `Global` flag. This means the regex won't stop searching after the first replace
Cerbrus
  • 70,800
  • 18
  • 132
  • 147
0
var str="+9(999)9999999";
alert(str.replace(/[()]/g,''));

DEMO

Prabhakaran Parthipan
  • 4,193
  • 2
  • 18
  • 27