且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

文本框的正则表达式 - 第一个字符必须是+或 - 后跟数字

更新时间:2022-12-27 22:25:51





但这是接受+++ 248.58或------ 528.88



只有第一个char必须是+或 - 从第二个char它必须只接受数字。请帮帮我。



我的尝试:



^ ([ - +] +(\d {1,10})(\.\d {2,2}))+


那是因为你告诉它了!

 [ -  +] + 

是正则表达式为'a' - '或'+ '性格,至少一个,但多到想要的。

取出重复指标,它应该有效:

 ^([ - ?+](\d {1,10})(\.\d {2,2}))+ 

I need to validate a textbox field that should accept first char as + or - and followed by decimal value

Ex: +248.58 or -528.88



I did a validation ^([-+]+(\d{1,10})(\.\d{2,2})?)+$

but this is accepting +++248.58 or ------528.88

only first char must be + or - from second char it must accept only numbers. Please do help me.

What I have tried:

^([-+]+(\d{1,10})(\.\d{2,2})?)+$



but this is accepting +++248.58 or ------528.88

only first char must be + or - from second char it must accept only numbers. Please do help me.

What I have tried:

^([-+]+(\d{1,10})(\.\d{2,2})?)+



That's becasue you told it to!
[-+]+

is Regex for "a '-' or '+' character, at least one, but as many as wanted.
Take out the repitition indicator and it should work:

^([-+](\d{1,10})(\.\d{2,2})?)+