473,586 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

email validation function

Hello,
I need help with the following code. Would be very grateful for
comments.
I have a function called emailValid, and it is supposed to alert the
user if h/she leaves the field blank. I want to run this function
before the ComputeCost function but don't know how to go about doing
it.
Thanks in advance.
Roohbir

<html>
<head>
<script type="text/javascript" src="myOwnJavaS cript.js">
</script>
</head>

<body>
<script type="text/javascript">

function emailValid()
{
email = sampleform.text 2.value
if (email == "") {
alert("Invalid email address") // cannot be empty
return false
}

return true
}

function ComputeCost()
{
//create an object
obj = new ShippingInfo(sa mpleform.menu1. value,
sampleform.menu 2.value, sampleform.text 1.value, sampleform.text 2.value)

//add a method
obj.GetShipping Cost=GetShippin gCost;

//Invoke a method.
var Cost = obj.GetShipping Cost();
var message = document.getEle mentById("myOwn divElement");
message.innerHT ML = "Cost = " + Cost;
return false;

}
</script>
<form name="samplefor m" onsubmit="Compu teCost();return false;">

<p>Shipping Destination:
<select name="menu1">
<option value="">--Select a destination--</option>
<option value="Boston"> Boston</option>
<option value="Seoul">S eoul</option>
</select>
<p>Shipping Type:
<select name="menu2">
<option value="">--Select a delivery method--</option>
<option value="Express Delivery">Expre ss Delivery</option>
<option value="Standard Delivery">Stand ard Delivery</option>
</select>
<p>Receiver:
<input name="text1" type="text" size="20"></input>

<p>Receiver's Email Address:
<input name="text2" type="text" size="20"
onchange="email Valid();"></input>

<p><input type="submit" value="Submit">

<div id="myOwndivEle ment"></div>
</form>
</body>
</html>

Oct 31 '06 #1
4 2012

roohbir wrote:
Hello,
I need help with the following code. Would be very grateful for
comments.
I have a function called emailValid, and it is supposed to alert the
user if h/she leaves the field blank. I want to run this function
before the ComputeCost function but don't know how to go about doing
it.
Thanks in advance.
Roohbir

<html>
<head>
<script type="text/javascript" src="myOwnJavaS cript.js">
</script>
</head>

<body>
<script type="text/javascript">

function emailValid()
{
email = sampleform.text 2.value
if (email == "") {
alert("Invalid email address") // cannot be empty
return false
}

return true
}

function ComputeCost()
{
//create an object
obj = new ShippingInfo(sa mpleform.menu1. value,
sampleform.menu 2.value, sampleform.text 1.value, sampleform.text 2.value)

//add a method
obj.GetShipping Cost=GetShippin gCost;

//Invoke a method.
var Cost = obj.GetShipping Cost();
var message = document.getEle mentById("myOwn divElement");
message.innerHT ML = "Cost = " + Cost;
return false;

}
</script>
<form name="samplefor m" onsubmit="Compu teCost();return false;">

<p>Shipping Destination:
<select name="menu1">
<option value="">--Select a destination--</option>
<option value="Boston"> Boston</option>
<option value="Seoul">S eoul</option>
</select>
<p>Shipping Type:
<select name="menu2">
<option value="">--Select a delivery method--</option>
<option value="Express Delivery">Expre ss Delivery</option>
<option value="Standard Delivery">Stand ard Delivery</option>
</select>
<p>Receiver:
<input name="text1" type="text" size="20"></input>

<p>Receiver's Email Address:
<input name="text2" type="text" size="20"
onchange="email Valid();"></input>

<p><input type="submit" value="Submit">

<div id="myOwndivEle ment"></div>
</form>
</body>
</html>
I have a function in PHP to do this, you have to do it server side
again, only in this case it's really secure:

function validMail($data , $strict=false)
{
$regex = $strict ?
'/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i' :
'/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i';
return preg_match($reg ex, trim($data));
}

I think it's easy to port this function to JS, else ask me again.

Andi

Oct 31 '06 #2
Actually, I don't need Server side coding here because the function
will alert the user if the user fails to enter anything in the email. I
just wanted to know how I can use this function before the ComputeCost
function. I mean, on submitting the form, till now the application's
event handler was ComputeCost.
Hope this explains it a little bit.
Cheers
Roohbir

On Oct 30, 8:22 pm, "webEater" <andreaskal...@ gmx.dewrote:
roohbir wrote:
Hello,
I need help with the following code. Would be very grateful for
comments.
I have a function called emailValid, and it is supposed to alert the
user if h/she leaves the field blank. I want to run this function
before the ComputeCost function but don't know how to go about doing
it.
Thanks in advance.
Roohbir
<html>
<head>
<script type="text/javascript" src="myOwnJavaS cript.js">
</script>
</head>
<body>
<script type="text/javascript">
function emailValid()
{
email = sampleform.text 2.value
if (email == "") {
alert("Invalid email address") // cannot be empty
return false
}
return true
}
function ComputeCost()
{
//create an object
obj = new ShippingInfo(sa mpleform.menu1. value,
sampleform.menu 2.value, sampleform.text 1.value, sampleform.text 2.value)
//add a method
obj.GetShipping Cost=GetShippin gCost;
//Invoke a method.
var Cost = obj.GetShipping Cost();
var message = document.getEle mentById("myOwn divElement");
message.innerHT ML = "Cost = " + Cost;
return false;
}
</script>
<form name="samplefor m" onsubmit="Compu teCost();return false;">
<p>Shipping Destination:
<select name="menu1">
<option value="">--Select a destination--</option>
<option value="Boston"> Boston</option>
<option value="Seoul">S eoul</option>
</select>
<p>Shipping Type:
<select name="menu2">
<option value="">--Select a delivery method--</option>
<option value="Express Delivery">Expre ss Delivery</option>
<option value="Standard Delivery">Stand ard Delivery</option>
</select>
<p>Receiver:
<input name="text1" type="text" size="20"></input>
<p>Receiver's Email Address:
<input name="text2" type="text" size="20"
onchange="email Valid();"></input>
<p><input type="submit" value="Submit">
<div id="myOwndivEle ment"></div>
</form>
</body>
</html>I have a function in PHP to do this, you have to do it server side
again, only in this case it's really secure:

function validMail($data , $strict=false)
{
$regex = $strict ?
'/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i' :
'/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i';
return preg_match($reg ex, trim($data));

}I think it's easy to port this function to JS, else ask me again.

Andi
Oct 31 '06 #3

Well, the regex below will cover emails with alphanumeric ones including -
and ., you can add more if you wish though barely necessary most likely :) .

<form name="samplefor m" onsubmit="retur n ComputeCost()">

<input name="text2" type="text" size="20" onchange="email Valid(this);">

---------------------------

function emailValid(el)
{
em=/[\w-\.]+@[\w-\.]+[a-z]+/i;
if (!em.test(el.va lue)) {
alert('yo buddy, enter a correct email please');
el.select();
}
}
Danny
Oct 31 '06 #4
roohbir wrote:
I have a function called emailValid, and it is supposed to alert the
user if h/she leaves the field blank. I want to run this function
before the ComputeCost function but don't know how to go about doing
it.
Thanks in advance.
Roohbir

<html>
<head>
<script type="text/javascript" src="myOwnJavaS cript.js">
</script>
</head>

<body>
<script type="text/javascript">
function CallTwoFunction s()
{
if (emailValid()) ComputeCost();
}
>
function emailValid()
{
<snip>
}

function ComputeCost()
{
<snip>
}
</script>
<form name="samplefor m" onsubmit="Compu teCost();return false;">
<form name="samplefor m" onsubmit="CallT woFunctions();r eturn false;">

<snip>

--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
Oct 31 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
6463
by: Dynamo | last post by:
Hi The following script was taken from John Coggeshall's (PHP consultant) in his article on Zends site at http://www.zend.com/zend/spotlight/ev12apr.php // Get the email address to validate $email = $_POST // Use John Coggeshalls script to validate the email address if(!eregi("^+(\.+)*@+(\.+)*(\.{2,3})$", $email) { echo "The e-mail was...
4
1793
by: VbUser25 | last post by:
Hi Please suggest i think i am doing something wrong. I am calling fucntion test from another function where i am performing all the validations.I want to validate the email id. this is the main function where i perform all sort of mandatory validation==> if (document.f.repemail.value != ""){ if(test(document.f.repemail.value=false)) {
2
2361
by: Tim Mills | last post by:
The following code asks the user to sumbit a name, email address, and some text for a quotation via a FORM. I have written a javascript function to evaluate the fields in the form and pop-up a message to tell the user if all the fields have been fill-out. If the user has missed some information the form re-displays with red "alerts" indicating...
12
5005
by: Dag Sunde | last post by:
My understanding of regular expressions is rudimentary, at best. I have this RegExp to to a very simple validation of an email-address, but it turns out that it refuses to accept mail-addresses with hypens in them. Can anybody please help me adjust it so it will accept addresses like dag-sunde@test-domain.net too?
3
1748
by: Shapper | last post by:
Hello, I have an aspx.vb code with a function. In this function I need to check if a variable is a valid email address. Something like: address@domain.extension How can I do this? Thanks,
35
3342
by: Mika M | last post by:
Simple question: Does Framework (1.1) contain any routine to check entered email-address is valid ? It's quite easy to make own code for that purpose, but why to do if Framework (1.1) contain this kind of routine. -- Thanks in advance! Mika
7
3041
by: e_matthes | last post by:
Hello everyone, I've read enough about email validation to know that the only real validation is having a user respond to a confirmation message you've sent them. However, I want to store the address temporarily, so I want to make sure what is entered is safe to work with. I have a basic understanding of regexps, so I could write one that...
10
30226
by: ll | last post by:
Hi, I currently am using the following regex in js for email validation, in which the email addresses can be separated by commas or semicolons. The problem, however, lies in that I can type two emails (as a run-on, with no comma or semicolon), and as long as it ends in a three character domain, it is accepted as valid. I wonder if there...
4
8746
by: JvC | last post by:
Does anyone have a good routine for EMail address validation? The one that I use is fairly primitive, and I need to beef it up. I have downloaded several from the web, and they all get screwed up by one thing or another, and tell me valid addresses are invalid. Thanks! John
5
1370
by: Morgan Packard | last post by:
Hello, Is there a generally accepted technique for client-side email address validation? Can someone point me to a good, widely-used and tested script? thanks, -morgan
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.