开发者

Regex test for NUMBERS

I have found a Regex that test if the text passed to a TextBox is an email.

If Regex.IsMatch(email.Text, "^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))" +  "(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$") _
Then
// True
End If

I want to change this, so it will test if the text type开发者_C百科d is just Numbers ?

How can I do that ?


If you want to make sure the text contains only digits use a simple ^\d+$ or ^\s*\d+\s*$ to allow some spaces at the beginning and end.

To allow negative numbers: ^-?\d+$ or ^[+-]?\d+$ to allow numbers like +12

For decimal numbers: ^[+-]?\d+(\.\d+)?$ (this will allow 0.54 but not .54)

This one will allow things like .54

^[+-]?(\d+(\.\d+)?|\.\d+)$


You might look at this answer for a definitive treatment of parsing numbers with regular expressions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜