[英]Acrobat Form Field RegEx Validation
I have a form field in my PDF that requires five capitalized letters as input, or nothing at all. 我的PDF中有一个表单字段,需要五个大写字母作为输入,或者根本不需要。 Everything else should result in an error.
其他一切都会导致错误。 I got the first part working, but I'm making some kind of mistake in checking for an empty field.
我得到了第一部分工作,但我在检查空场时遇到了一些错误。 Here's my Javascript:
这是我的Javascript:
event.rc = true; var myRegExp = /^[AZ]{5}$/; var myTextInput = event.value; if ( !myRegExp.test(myTextInput) || myTextInput != "" ) { app.alert("Your order number prefix must be formatted as five characters, all caps."); event.rc = false; }
Change the regex to 将正则表达式更改为
var myRegExp = /^([A-Z]{5})?$/;
to allow an empty string match and remove || myTextInput != ""
允许空字符串匹配并删除
|| myTextInput != ""
|| myTextInput != ""
condition that becomes irrelevant. || myTextInput != ""
条件变得无关紧要。
A (...)?
A
(...)?
group is an optional one because ?
组是可选的,因为
?
matches 1 or 0 occurrences of the quantified subpattern. 匹配量化子模式的1或0次出现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.