Older C# ASP.Net Web Form app with.Net Framework 4.6.2.
I have a regexp validator in an ascx user control:
<asp:RegularExpressionValidator ID="REV_RecordId" runat="server"
ControlToValidate="uxRecordID"
ValidationGroup="TheValidationGroup"
Display="Dynamic"
ForeColor="Red"
ErrorMessage="Please enter a valid ID"
SetFocusOnError="True"
ValidationExpression="^[-\wÀ-ÿ\'\.\-\&\s]+$" />
but when this control is loaded with
UserControl ctrl = (UserControl)LoadControl("path to user control");
I get the exception:
Inner Exception 1:
ArgumentException: parsing "^[-\wÀ-ÿ'.-&\s]+$" - [x-y] range in reverse order.
but any regex validator says "^[-\wÀ-ÿ'.-&\s]+$" is valid, the higher character component saying "matches a single character in the range between À (index 192) and ÿ (index 255) (case sensitive)".
So why would this fail with showing even stranger character interpretations?
is there an UTF16-encoded version of À and ÿ?
That is not the question you should be asking. The question you should be asking is "in which encoding have I saved the file containing my <asp:RegularExpressionValidator>
, and in which encoding should I have saved it instead?"
Your regex is seeing a different expression than the one you have written in the file, which is because the file is not being read in the same encoding you saved it in.