I'm struggling a little to get validation working on a signup form.
I have an email field that is both mandatory and with some regex to validate that it is a valid email.
When a user enters a valid email - then the form works fine, however if an invalid email address is entered, then the page does not display the expected little message as it does for mandatory items, instead taking the user to a page that simply reports "Specified cast is not valid".
Any advice on how to fix this would be much appreciated!
Heh, thank you for that - a good step in the right direction I think. The page shows a different error now of:
parsing "^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]$" - Too many )'s.
I tried the regex from the linked post, which returns the old "Specified cast is not valid" error
It seems strange that when inspecting the page, the form class="field-validation-valid" changes to valid when any data is input, and does not seem to check the regex at all!
I just tried to install the Contour 3.0.21 into a fresh Umbraco install version 7.1.8, and then I created a new form based on the standard pre-defined contact form.
And for the email field in the pre-defined contact form, it uses this regular expression:
I'm using Umbraco Contour version 3.0.21 and Umbraco 7.1.8
At this point - I'm doubting that it's the regex itself that is causing the issue: the field seems not to respond to input that is valid / invalid against regex in any way.
A regex on a test field of [abc] still will not give me any validation messages :(
The datepicker had had the date format changed to be in the UK format, and so changes were needed to FieldType.DatePicker.cshtml within the contour plugin folder.
We now parse the date using the following line:
d = DateTime.ParseExact(Model.Value, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
This removes the invalid cast errors, and the regex validation now triggers on other fields as expected.
Thanks for your help Dennis (I am using the updated email regex now also)
Specified cast is not valid when regex fails
Hi guys,
I'm struggling a little to get validation working on a signup form.
I have an email field that is both mandatory and with some regex to validate that it is a valid email.
When a user enters a valid email - then the form works fine, however if an invalid email address is entered, then the page does not display the expected little message as it does for mandatory items, instead taking the user to a page that simply reports "Specified cast is not valid".
Any advice on how to fix this would be much appreciated!
Screengrab of the email field:
Regex being used to validate emails:
Hi Sam,
To me it looks like that you are starting and ending your regular expression wrong.
I assme that you found the regex here: http://www.regular-expressions.info/email.html
Try this instead.
Or try to have a look on this post: http://our.umbraco.org/forum/umbraco-pro/contour/25041-regular-expression-for-valid-email-is-case-sensitive
Hope this helps,
/Dennis
Heh, thank you for that - a good step in the right direction I think. The page shows a different error now of:
I tried the regex from the linked post, which returns the old "Specified cast is not valid" error
It seems strange that when inspecting the page, the
form class="field-validation-valid"
changes to valid when any data is input, and does not seem to check the regex at all!Hi Sam,
What if you tried with this regex for validation of the email,
Did you still get the "Specified cast is not valid" error or?
Hope this helps,
/Dennis
Hi Dennis,
With that regex, I still see the same error of "Specified cast is not valid"
I've taken a grab of the source that is being formed by the field when it contains the data "asfd".
Hi Sam,
I just tried to install the Contour 3.0.21 into a fresh Umbraco install version 7.1.8, and then I created a new form based on the standard pre-defined contact form.
And for the email field in the pre-defined contact form, it uses this regular expression:
/Dennis
I'm using Umbraco Contour version 3.0.21 and Umbraco 7.1.8
At this point - I'm doubting that it's the regex itself that is causing the issue: the field seems not to respond to input that is valid / invalid against regex in any way.
A regex on a test field of [abc] still will not give me any validation messages :(
After all that - it turns out to be unconnected from the Regex!
The following link gave me a little insight: http://our.umbraco.org/forum/umbraco-pro/contour/49251-Specified-cast-is-not-valid?p=0
The datepicker had had the date format changed to be in the UK format, and so changes were needed to FieldType.DatePicker.cshtml within the contour plugin folder.
We now parse the date using the following line:
This removes the invalid cast errors, and the regex validation now triggers on other fields as expected.
Thanks for your help Dennis (I am using the updated email regex now also)
is working on a reply...