c# - Email Validation in .Net mvc4 -


currently using following code email validation validate dsgf@g mail id please me

[required(errormessage = "please enter email id")] [display(name = "email-id")] [emailaddress(errormessage = "invalid email address")] public string cust_email { get; set; } 

emailaddress attribute mark valid dsgf@g because valid email address, there nothing wrong method. consider example username@localhost example.

if not suits can use regular expression ti set own rule validation. try use 'regularexpression' attribute instead, like:

[regularexpression("^[^@\s]+@[^@\s]+(\.[^@\s]+)+$", errormessage = "invalid email address")] public string cust_email { get; set; } 

or

[regularexpression(@"^([a-za-z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-za-z0-9\-]+\.)+))([a-za-z]{2,4}|[0-9]{1,3})(\]?)$", errormessage = "invalid email address")] public string cust_email { get; set; } 

Comments

Popular posts from this blog

javascript - How do you prevent nested queries/catches in sequelize? -

java - Could not retrieve pre-bound Hibernate session - Could not obtain transaction-synchronized Session for current thread -

java - ConcurrentModificationException upon committing transaction with Hibernate -