Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old July 9th, 2003, 08:16 AM
jonathen jonathen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Essex, UK
Posts: 44 jonathen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Error trapping x@x.xxx in form

Hi all,

I have a javascript function I use for ensuring that the person filling in my form fills out each of the fields. This works well, but there is another feature I would like to add to it, but do not know what the syntax is, nor how I would be able to incorporate it into my current script without breaking it. I would like to ensure that not only does the person fill out all fields, including the email address field, but that if he/she was to fill out the email field with n/a or something that is not x@x.xxx (in other words a valid email string), it returns an alert alike to the ones I already use (in this case, telling the user to enter a real email address)

Any help is appreciated

This is my current script:

<!--
function checkform ( form )
{

// ** START **
if (form.name.value == "") {
alert( "Please enter your full name." );
form.name.focus();
return false ;
}
// ** END **
// ** START **
if (form.address.value == "") {
alert( "Please enter your full address." );
form.address.focus();
return false ;
}
// ** END **
// ** START **
if (form.postcode.value == "") {
alert( "Please enter your postcode." );
form.postcode.focus();
return false ;
}
// ** END **
// ** START **
if (form.phone.value == "") {
alert( "Please enter your phone number, including area code." );
form.phone.focus();
return false ;
}
// ** END **
// ** START **
if (form.emailaddr.value == "") {
alert( "Please enter your correct email address." );
form.emailaddr.focus();
return false ;
}
// ** END **
return true ;
}
//-->

Reply With Quote
  #2  
Old July 9th, 2003, 09:14 AM
Jester Jester is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: England
Posts: 271 Jester User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Error trapping x@x.xxx in form

Okay - I would go for a little bit of pattern matching (try the following for a taste):

Code:
<html>
<head>
<script type="text/javascript">
<!--
var pattern = new RegExp("(\w+)(@)(\w+)(\.)((\w{3})||\w{2}\.\w{2})$");
var text = "someone@somedomain.co.uk"; 
// could also be someone@somedomain.com
var result = pattern.test(text);
document.write(result);
//-->
</script>
</head>
<body>
</body>
</html>


if you look at the line:

RegExp("(\w+)(@)(\w+)(\.)((\w{3})||\w{2}\.\w{2})$");

what this does is matches a string and returns true or false if a good match is found - here we go:

(\w+) match any number of characters
(@) match an @ symbol
(\w+) then any characters again
(\.) then a fullstop
then (and I added a bit more)
((\w{3})||\w{2}\.\w{2}) match any 3 characters (e.g. com) OR any 2, a fullstop, then another 2 (e.g. co.uk)

The $ on the end means the pattern must match from the end of the string (i.e.) .com OR .co.uk at the end.

Hope this helps.

Reply With Quote
  #3  
Old July 9th, 2003, 09:48 AM
jonathen jonathen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Essex, UK
Posts: 44 jonathen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Error trapping x@x.xxx in form

Thank you for your very full response, that makes perfect sense... I'll give it a bash.


Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > Error trapping x@x.xxx in form


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT