开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜