Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 14th, 2004, 07:31 AM
Authorized User
 
Join Date: Oct 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default email validation check if it's correct?

Well I have this code :
<html>
<title</title>
<head>
<script Language="JavaScript">
function check_email(check) {
ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

for(i=0; i < e.length ;i++){
if(ok.indexOf(e.charAt )<0){
return (false);
}
}

/*function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@nackademin.com");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
    result = true;
  }
  return result;
}*/

function FormValidator(theForm)
{

  if (theForm.email.value == "" || ! "@nackademin.com")
  {
    alert("Please enter a valid emailadress in the \"email\" field.");
    theForm.email.focus();
    return (false);
  }

  if (!isEmailAddr(theForm.email.value))
  {
    alert("Please enter a complete email address in the form: your.name@nackademin.com");
    theForm.email.focus();
    return (false);
  }

  if (theForm.email.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"email\" field.");
    theForm.email.focus();
    return (false);
  }
  return (true);
}
</script>
</head>
<body>
<form method="POST" action="feedback.html" onsubmit="return FormValidator(this)" id=form4 name=form4>
  <p>Email Address: <input type="text" name="email" size="32"><input type="submit"
  value="Submit" name="submit"></p>
</form>
</body>
</html>

This code has to check if the mail is sent either to www.nackademin.com or to www.lexikon.se and that there is at least one letter before the @ , no numbers! and if there's an @ in the address.
Can someone check this out and tell me what to do?



 
Old October 14th, 2004, 10:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Regular Expressions are your best bet here. You can do all those checks in one go. Something like this should do the trick:
^([A-Za-z]+\.+)*[A-Za-z]+@((nackademin.com)|(lexikon.se))$

use code like this to run it:
Code:
if ( /^([A-Za-z]+\.+)*[A-Za-z]+@((nackademin.com)|(lexikon.se))$/.test(theForm.email.value) )
{
    alert("email good);
}
else
{
    alert("email bad");
}
rgds
Phil
 
Old October 14th, 2004, 01:51 PM
Authorized User
 
Join Date: Oct 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanxs!!!!!I'll try it later!!!!!!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
JS to check for form Validation does not work - pl jennypretty Classic ASP Basics 4 December 11th, 2008 11:18 PM
SQL Install Validation Check Sebastiaan SQL Server 2000 0 March 8th, 2006 10:37 AM
check is column name is correct ryanvdmerwe Classic ASP Basics 3 March 15th, 2004 03:12 PM
email validation tysta JSP Basics 3 June 23rd, 2003 12:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.