Question

I have to build a custom module in which i have added a custom fields on to the customer registration page a fields like alternate mail id,mobile number & etc which is successfully getting saved in my database & here i have to implement a one more feature that is

on registration page when user enters his email id that should check for the domain name.

Ex: my domain name is abc & the users mail address will be user@abc.com

& the users of "abc.com" should only has to get register into my online store How do i restrict the users of other domain apart from abc.com

Please help me in doing this.....

Was it helpful?

Solution

You can use regular expression for this. Just use the below function:

function checkEmail($email) {
  if(preg_match("/^([a-zA-Z0-9\._-])*@abc.com$/",$email)){

    return true;
  }
  return false;
}

Code Edited

    <script type="text/javascript">
    function validateEmail(elementValue){  
       var emailPattern = /^[a-zA-Z0-9._-]+@abc.com$/;  
       return emailPattern.test(elementValue);  
     }  

    function checkForm(){
        var emailId = document.getElementById('email_address').value;
        if(! validateEmail(emailId)) {
            alert("Email id is not valid");
        }
    }
</script>

<div class="input-box"style="width: 550px;"> 
    <input type="text" name="email" id="email_address" value="<?php echo $this->htmlEscape($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" /> 

    <input type="submit" value="Click here" onclick="checkForm()" />(There will be be an submit button put the onclick event in it)

</div> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top