开发者

Need help for regular expression for percent value

I am trying to pass value as 95%

numexu = 95%
"^((>|GT|>=|GE|<|LT|<=|LE|==|EQ|!=|NE)?\\s*\\d?[%]?)$
 if (!regex.IsMatch(numexu))
            throw new ArgumentException("Percent expres开发者_高级运维sion is in an invalid format.");

it is throwing exception in code.

Regards, Regex


You are checking only for 1 number \\d?, try instead this: \\d{0,2}, this accepts 0, 1 or 2 numbers. The ? makes it 0 or 1 times matching.

I am not sure if you need to escape the %, if so then \\%. Additionally if you have only one character you can skip the brackets [%], so % (or \\%, if needed to escape)


   This Function will work for your requirement 

 function check() {
     var txtfield; txtfield =document.getElementById('txtbox').value; 
     var reg=/^(\d{0,2}%?$)/;
     if(reg.test(txtfield)){
     alert("match");

     }
     else { alert("Try again"); } 
      }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜