Flex中对同一控件如TextInput进行多种格式校验的情况下,如不注意,可能导致错误信息不显示的BUG,比如
< fx:Array id ="validators" >
< mx:RegExpValidator source ="{txtNewPass}" property ="text" required ="true" requiredFieldError ="请输入新密码"
expression ="^(?:(?=.*[a-zA-Z])(?=.*[0-9])).\{8,\}$" noMatchError ="密码长度不少于8位,至少包含数字和字母" /> < cn:CompareValidator source ="{txtNewPass}" property ="text" required ="false"
comparer ="{txtOldPass.text}" comparable ="true" compareError ="新密码与原密码相同" />
</ fx:Array >
这种情况下会发现txtNewPass这个TextInput的错误提示无法显示,我试了很久,发现原因在于 required="true" requiredFieldError="请输入新密码" ,必须放在最后一个校验器中,而 前面的必须设置required="false" ,很奇怪,算是一个小BUG了,正确写法:
< fx:Array id ="validators" >
< mx:RegExpValidator source ="{txtNewPass}" property ="text" required ="false"
expression ="^(?:(?=.*[a-zA-Z])(?=.*[0-9])).\{8,\}$" noMatchError ="密码长度不少于8位,至少包含数字和字母" /> < cn:CompareValidator source ="{txtNewPass}" property ="text" required ="true" requiredFieldError ="请输入新密码"
comparer ="{txtOldPass.text}" comparable ="true" compareError ="新密码与原密码相同" />
</ fx:Array >