我想要的是一个最大长度为5的文本框。允许的值有:
所以我认为应该:
但它没有输出任何东西..
这是 jsfiddle 的链接:http://jsfiddle.net/Fs6aq/4/。
ps:那里的 pattern1 和 pattern2 与我之前的问题有关,详情请参见此处。
- 任何整数 // 例如 1、3、9、9239 都是有效的
- 实数,小数点后恰好有一位 // 例如 1.2、93.7 是有效的,61.37、55.67 是无效的
- 也可以只输入小数点和一位数字,即 .7 是有效的输入(将被视为 0.7)
所以我认为应该:
- 存在一个数字
- 如果有一个数字和小数点,在小数点后必须有一个数字
- 如果没有数字,则必须有一个小数点和一个数字
a single digit one or more => /d+
an optional decimal point followed by exactly one digit => (?:[.]\d{1})?
if first condition matches => (?(first condition) => (?((?<=\d+)
then, match the option decimal and one exact digit =>(?((?<=\d+)(?:[.]\d{1})?
else => |
find if there is a decimal and one exact digit => (?:[.]\d{1}){1}
check the whole condition globally => /gm
总体表达 =>
(?(?<=\d+)(?:[.]\d{1}){1}|(?:[.]\d{1}){1})+/gm
但它没有输出任何东西..
这是 jsfiddle 的链接:http://jsfiddle.net/Fs6aq/4/。
ps:那里的 pattern1 和 pattern2 与我之前的问题有关,详情请参见此处。