对于相同的ID,我必须有两种不同的正则表达式模式。原因是我对所有三个都有不同的错误消息要求。问题是最后一个正则表达式干扰了第二个领先的空间验证。我尝试了\s
,^\s
,[ \t]
,(?! )
以及我提出的各种其他难以想象的想法。与上面相同的正则表达式与StreetAddress2冲突并允许前导空格。我试过的修剪没有奏效。除非我注释掉SameAsAbove。
public const string StreetAddress = @"^(?!(SAME|SAME AS ABOVE|same|same as above))[a-zA-Z0-9]{1}[a-zA-Z0-9&-\/.# ]{0,49}";
public const string StreetAddress2 = @"^(?! )[^\s][a-zA-Z0-9]{1}[a-zA-Z0-9&-\/.# ]{0,49}";
public const string SameAsAbove = @"^(?!(SAME|SAME AS ABOVE|same|same as above|Same|Same as above|Same as Above)).*$";
前两个给出了信息:
public const string StreetAddress = "Street may contain only alphanumeric characters, ., #, /, -, & or white space";
最后一条给出了这条消息:
public const string SameAsAbove = "Same or Same As Above is not allowed";
<asp:RegularExpressionValidator
ID="RegExpDFSRegistrationAddress"
ControlToValidate="txtDFSRegistrationAddress"
runat="server"
CssClass="Error" />
RegExpBusinessContactAddress.ValidationExpression = CommonRegularExpressions.StreetAddress2;
RegExpBusinessContactAddress.ErrorMessage = CommonErrorMessages.StreetAddress;