Reputation: 664
I am using razor view in my application. I am trying to validate my mailID. I got email pattern format like,
function validateEmail(mail) {
var emailPattern = var emailPattern = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
if (emailPattern.test(mail) == false) {
$("#emailvalidation").text("Email is not in correct format");
}
else if (emailPattern.test(mail) == true) {
}
}
but If I give this in my function,It is displaying error at the "@" symbol. can any one help me,how to fix this.
Upvotes: 1
Views: 142
Reputation: 91
I am trying to restrict the user not to insert more than two domain after the '@'.
/^[\w-_$\.]+@[\w]+((\.)((\w){2,4})){1,2}$/
Upvotes: 0
Reputation: 664
I gave like, var emailPattern = /^[a-zA-Z0-9_.-]+@@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{0,4}$/; I used "@" twice. it is working fine in my case.
Upvotes: 0
Reputation: 17680
Change this line.
var emailPattern = var emailPattern = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
To this
var emailPattern = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
See the associated jsfiddle
Upvotes: 1
Reputation: 516
because Razor code blocks are enclosed in @{ ... }, Inline expressions (variables and functions) start with @, Code statements end with semicolon.
Upvotes: 1