开发者

How to allow only "numbers","-" and "()" using JavaScript

开发者 https://www.devze.com 2023-01-18 05:26 出处:网络
I开发者_运维技巧 have to do phone number validation using JavaScript. I have already done validation for numbers as follows,

I开发者_运维技巧 have to do phone number validation using JavaScript.

I have already done validation for numbers as follows,

  
var filter =/^[0-9]+$/

But now I have to also allow hyphen and "()".

Please provide me a way for the same.


How about:

/^[0-9()-]+$/

Notes:

  • Parenthesis have no special meaning in a character set
  • If you start, or end, with a minus-sign, it is not interpreted as a range, but as the minus-character itself
0

精彩评论

暂无评论...
验证码 换一张
取 消