Email validation to allow 2 domains


hi everyone,
needed create validation form allow 2 domains (basic check if @abd.com or @asd.com , allow only).

it's plain javascript, can give me suggestions?

:confused:

of today validation this:

php:
function validateform()
{
var 
x=document.getelementbyid("user_email").value;
var 
atpos=x.indexof("@thisdomain.com");
var 
dotpos=x.lastindexof(".");
if (
atpos<|| dotpos<atpos+|| dotpos+2>=x.length)
  {
  
alert("please use your @thisdomain.com email address");
  return 
false;
  }
}
 

here's tweaked function uses regular expression check 2 domains being present. in case valid domains thatdomain.com , thisdomain.com. ensures there @ least 2 characters before @ characters , no spaces anywhere. added else piece testing purposes.

php:
function validateform() {
    var 
document.getelementbyid("user_email").value;
    var 
regex = new regexp(/^[\w\.\+_-]+[\w]+@(this|that)domain\.com$/);
    
// validate email address
    
if (!regex.test(x)) {
        
alert("please use your @thisdomain.com or @thatdomain.com email address.");
        return 
false;
    }
    else {
        
alert('address valid.');
    }
}
 


Forums Special Interests Web Design and Development


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

Comments

Popular posts from this blog

Mac OS X Server as File Server for 50/50 Mac & PC Workgroup

Permissions Problem?

iPhone won't sync with iTunes