The [Email] attribute in Asp.Net MVC4 does not allow white space on the client side, does anyone know how i can allow something like " myemail@email.com " to pass through the unobtrusive java script generated by the property decorators?
When it hits Http Post, i can trim() the model.Email before doing anything with it. I just need to get past client validation.
I'm guessing any valid email regex will work if i tack on \\s* at the start and end of the pattern?
Thanks!
You can use jQuery to trim the textbox value. Something like:
$("#textboxId").on("change", function () {
$(this).val($.trim($(this).val()));
}
好的,我想我应该在发布之前测试过它,但是是的,您可以加上\\ s *,这样就可以忽略空格..这里我最终使用的正则表达式
[RegularExpression(@"^(\s*[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9}\s*)$")]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.