5 Replies - 1149 Views - Last Post: 09 May 2012 - 07:54 AM

#1 monstratonis  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 18-April 10

simple email validation

Posted 08 May 2012 - 10:16 AM

hi there,

have these simple code for email validation but I am stuck as I want to predefine gmail emails to give ex discount...

here is the code:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Check Email Address</title>
<script language="javascript">
function checkEmail(inputvalue){
var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
if(pattern.test(inputvalue)){
alert("true");
}else{
alert("false");
}
}
</script>
</head><body>
<form name="signupform">
Input your email: <input name="email" type="text" class="inputs" id="email_address"
value="any@any.com" size="35" maxlength="255">
<input name="summit" type="submit" value="Check" onclick="checkEmail(document.signupform.email.value)">
</form></body></html>



but when i change that code to recognize gmail

<script language="javascript">
function checkEmail(inputvalue){
var pattern=/^([a-zA-Z0-9_.-])+@(gmail])+\.([a-zA-Z])+([a-zA-Z])+/;
if(pattern.test(inputvalue)){
alert("true");
}else{
alert("false");
}
}
</script>

only gmail accounts are valid
any chance to implement @(gmail]) & @([a-zA-Z0-9_.-]) ? :)

Is This A Good Question/Topic? 0
  • +

Replies To: simple email validation

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: simple email validation

Posted 08 May 2012 - 11:14 AM

Had you considered you could do 2 checks? Since both codes work for their situation you could check if either is valid

If (IsRegularEmail || IsGmail) return true;
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: simple email validation

Posted 08 May 2012 - 10:27 PM

note, gmail also uses the googlemail.com domain.
Was This Post Helpful? 1
  • +
  • -

#4 monstratonis  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 18-April 10

Re: simple email validation

Posted 09 May 2012 - 01:50 AM

thanks for your responses the two checks would be good to pass the login but I dont really see how to fix the code to be able to give a discount if you log in with gmail email ...
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: simple email validation

Posted 09 May 2012 - 06:29 AM

Set a variable like DiscountPercentage to whatever amount you like.
If they have a gmail account set it to 10. If they have a regualar account set it to 5.
Was This Post Helpful? 0
  • +
  • -

#6 monstratonis  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 63
  • Joined: 18-April 10

Re: simple email validation

Posted 09 May 2012 - 07:54 AM

yes thank you :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1