1

I'm trying to get someone to use a specific email domain of @mail.fhsu.edu. Here is my Validation code.

 function validateFHSUEmail(inputField, helpText) {
    if (inputField.value.length == 0) {
        if (helpText != null) {
            helpText.innerHTML = "Please Enter a Value";    
        }
        return false;
    } else {
        var reg = /^[a-z.][email protected]$/;
        if (!reg.test(inputField)) {
            if (helpText != null) {
            helpText.innerHTML = "Please Enter FHSU Email"; 
            }

Am I calling it wrong or what because no matter what it returns false.

2
  • 1
    FYI, you'll need to change any .s in your regex to \. - . is a special character meaning "any single character can match here". Commented Oct 21, 2013 at 22:09
  • @michaelb958 not inside a [ ] group but otherwise good catch. Commented Oct 21, 2013 at 22:10

2 Answers 2

3

You're testing the variable "inputField", which apparently is a reference to a DOM element. You want inputField.value in the test.

edit Note the comment wherein it's pointed out that your regex should use \. for the periods in the domain name.

Sign up to request clarification or add additional context in comments.

Comments

0

If you want valid email and specific domain try this regex:

/^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@domain.com$/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.