1

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.

4

4 回答 4

1

because Razor code blocks are enclosed in @{ ... }, Inline expressions (variables and functions) start with @, Code statements end with semicolon.

于 2012-12-29T09:13:06.080 回答
1

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

于 2012-12-29T09:21:35.387 回答
0

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.

于 2012-12-29T10:00:10.113 回答
0
I am trying to restrict the user not to insert more than two domain after the '@'. 

/^[\w-_$\.]+@[\w]+((\.)((\w){2,4})){1,2}$/
于 2017-04-01T18:36:03.840 回答