开发者

How to validate input using JavaScript?

I am to check the number of occurrenc开发者_如何转开发es of a numeric value in a string i.e in that string only 2 numeric characters are allowed. Can anyone help me to solve this?

Thanks in advance


Try this code

    var s ="1asds3asa"; // string to check
    var t = s.replace(/[^\d]/g,""); // a string with everything but the digits removed
    if(t.length>2)
    {
       alert("Only 2 numbers allowed");
    }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜