大佬教程收集整理的这篇文章主要介绍了jquery – 英尺和英寸的正则表达式 – 带小数和分数,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个好的开始,但我不是正则表达的主人,觉得我太复杂了我的模式.因此允许以下值:
5 6(英尺和英寸用空格隔开)
5’6“(英尺和英寸格式正确)
5.2 6(以空格分隔的十进制英尺)
5.2’6“(十进制英尺,格式正确)
5 6.1(以空格分隔的十进制英寸)
5’6.1“(十进制英寸,格式正确)
5.2 6.1(以空格分隔的十进制英尺和英寸)
5.2’6.1“(十进制英尺和英寸格式正确)
5 6 1/2(以上任何组合后跟空格和分数)
5.2’6.1 1/2“(再次带小数)
78“(仅英寸)
78.4“(仅带小数的英寸)
我知道,相当挑剔.我有一些正在进行中的工作,我已将其分解为更具可读性(至少对我自己而言). http://jsfiddle.net/t37m0txu/383/
// allow numbers var p_num = "[0-9]"; // numbers are up to 9 characters (it needs a range,for some reason) var p_range = "{0,9}"; // allow a single decimal var p_dec = "([.]{0,1})"; // allow a single space (needs to happen only if not directly followed by a decimal) var p_space = "([ ]{0,1})"; // numbers,possible single decimal and/or space var p_base = p_num + p_range + p_dec + p_space; // only allow a single/double quote after a number var p_afternum = "?(?=" + p_num + ")"; // allow a single or double quote var p_quote = "(\'(0?" + p_base + ")?\|\"$)"; // issues: // i do not need a range/cap on numbers // after using decimal or space - only one number is allowed to follow (do not cap the range on numbers,only decimal/spacE) // do not allow a space directly following a decimal // do not allow a decimal directly following a single or double quote var ex = "(" + p_base + ")" + p_afternum + p_quote + "(0?" + p_base + ")?\""
此扫描使用REGEX蒙版与输入蒙版相结合来创建功能强大的英尺和英寸文本框.
ex = "[\\d]+(?:\\.[\\d]+|)(?:\\s\\d+\\/\\d+|)(?:\\s|\\'|\\\"|)[\\d]+(?:\\.[\\d]+|)(?:\\s\\d+\\/\d+|)(?:\\'|\\\"|)"; $('#feet').inputmask('Regex',{ regex: ex });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://rawgit.com/RobinHerbots/jquery.inputmask/3.x/dist/jquery.inputmask.bundle.js"></script> So the following values are allowed:<br /><br /> 5 6 (feet and inches separated by spaces)<br /> 5'6" (feet and inches in the correct format)<br /> 5.2 6 (decimal feet separated by spaces)<br /> 5.2'6" (decimal feet in the correct format)<br /> 5 6.1 (decimal inches separated by spaces)<br /> 5'6.1" (decimal inches in the correct format)<br /> 5.2 6.1 (decimal feet and inches separated by spaces)<br /> 5.2'6.1" (decimal feet and inches in the correct format)<br /> 5 6 1/2 (any combination above followed by a space and fraction)<br /> 5.2'6.1 1/2" (again with decimals)<br /> 78" (only inches)<br /> 78.4" (only inches with a decimal)<br /> <input id="feet" /> <br />
以上是大佬教程为你收集整理的jquery – 英尺和英寸的正则表达式 – 带小数和分数全部内容,希望文章能够帮你解决jquery – 英尺和英寸的正则表达式 – 带小数和分数所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。