允许小数和整数的正则表达式 [英] regular expression which allow both decimals as well as integers

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

问题描述

大家好,

我需要编写一个正则表达式,该表达式允许使用
这样的数字
1.23



1

进入文本框.小数点不是强制.

欢迎任何建议或链接.. !!

Hello everyone,

I need to write a regular expression which will allow numbers like

1.23

and

1

in to the text-box. Decimal point is not the compulsion.

Any suggestion or links are welcome..!!

推荐答案

正则表达式为: ^ [0-9] \ d {0,9}(\. \ d {1,3})?%?
Regular Expression is : ^[0-9]\d{0,9}(\.\d{1,3})?%?




[0-9]:用于允许从0到9的整数的整数
d {0,9}:最多需要10位数字
\. :十进制
d {1,3}:十进制最多三位数字


[0-9] : for integers which allows integers from 0 to 9
d{0,9}: this will take up to 10 digits
\. : for decimal
d{1,3} : for decimal up to three digits


范围为1-9的数字,后跟零个或多个其他数字:
A digit in the range 1-9 followed by zero or more other digits:
^[1-9]\d*


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

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