Vijin Paulraj
Vijin Paulraj

Reputation: 4618

Email validation for a ValidationTextBox in dojo?

I'm working with dojo1.7 and here i'm looking for a regex that will validate an Email address and here i'm using the widget dijit.form.ValidationTextBox.I've googled enough,but found nothing.

Here is the code and i left the regExp property empty.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Email Validation</title>
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7/dijit/themes/claro/claro.css">
    <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.7/dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: true"></script>
    <script>
        require(["dojo/parser", "dijit/form/ValidationTextBox"]);
    </script>
</head>
<body class="claro">
    <label for="email">Enter your Email Address:</label>
    <input type="text" name="email" value=""
    data-dojo-type="dijit.form.ValidationTextBox"
    data-dojo-props="regExp:'', required:true, invalidMessage:'Invalid Email Address.'">
</body>
</html>

Please someone help me to find the regular expression.!

Upvotes: 0

Views: 6895

Answers (3)

Ortega Marco Antonio
Ortega Marco Antonio

Reputation: 41

If you want to validate optional email address just use the following JavaScript code.

dijit.byId("newuser_email2").validator = function(value, constraints){
    if(value == ''){
      return true;
    }
    return dojox.validate.isEmailAddress(value, constraints);
}

Remember to replace your input id in my case I'm using newuser_email2.

Upvotes: 4

naaronne
naaronne

Reputation: 13

  var emailField = new ValidationTextBox({
        required: true,
        validator: validateWeb.isEmailAddress
    }, "emailField");

Upvotes: 1

Craig Swing
Craig Swing

Reputation: 8162

dojox.validate.regexp has some regexes for common data including email

regExp: dojox.validate.regexp.emailAddress

Upvotes: 2

Related Questions