正则表达式测试NUMBERS [英] Regex test for NUMBERS

查看:69
本文介绍了正则表达式测试NUMBERS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一个 Regex ,用于测试传递到TextBox的文本是否为电子邮件.

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

我想更改此设置,因此它将测试键入的文本是否只是 Numbers 吗?

I want to change this, so it will test if the text typed is just Numbers ?

我该怎么做?

推荐答案

如果要确保文本仅包含数字,请使用简单的 ^ \ d + $ ^ \ s *\ d + \ s * $ 允许在开头和结尾留一些空格.

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.

要允许负数: ^-?\ d + $ ^ [+-]?\ d + $ 允许类似 +12

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

对于十进制数字: ^ [+-]?\ d +(\.\ d +)?$ (这将允许 0.54 ,但不允许 .54 )

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

这将允许 .54

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

这篇关于正则表达式测试NUMBERS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆