Hi every one, newbie here, so i big hello from me now down to business
I am a web developer but i don't use java script very often, but i have created a form validation from a group of different tutorial, but have run in to a brick wall trying to create a function to compare the email addresses and validate that they are the same because of the combination of different tutorial i have used.
here is the code the function is called "emailval" if anyone with a better knowledge of javascript than me could give me a head up on what missing i would be most grateful. - function emailvalidation(entered, alertbox)
-
{
-
-
with (entered)
-
{
-
apos=value.indexOf("@");
-
dotpos=value.lastIndexOf(".");
-
lastpos=value.length-1;
-
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2)
-
{if (alertbox) {alert(alertbox);} return false;}
-
else {return true;}
-
}
-
}
-
-
function emptyvalidation(entered, alertbox)
-
{
-
-
with (entered)
-
{
-
if (value==null || value=="")
-
{if (alertbox!="") {alert(alertbox);} return false;}
-
else {return true;}
-
}
-
}
-
-
function emailval(thisform)
-
{
-
-
if (entered.value != second.value)
-
{if (alertbox) {alert(alertbox);} return false;}
-
else {return true;}
-
}
-
-
-
-
-
function formvalidation(thisform)
-
{
-
with (thisform)
-
{
-
if (emailval(email,emailtwo,"The two e-mail addresses do not match")==false) {emailtwo.focus(); return false; email.focus(); return false;};
-
if (emailvalidation(email,"Your E-mail Address Is Not Valid")==false) {email.focus(); return false;};
-
if (emptyvalidation(name,"Please Enter Your Name")==false) {name.focus(); return false;};
-
if (emptyvalidation(message,"Please Enter Your Equiry")==false) {message.focus(); return false;};
-
if (emailvalidation(emailtwo,"Your E-mail Address Is Not Valid")==false) {emailtwo.focus(); return false;};
-
-
-
-
-
}
-
}
-
8 1817
if (emailaddy == otheremailaddy) { alert("Congrats they match!"); return true; } else { return false; }
gits 5,390
Expert Mod 4TB
hi,
yes ... ;) that is much better ... but i think that's the one half of his problem ... he also wants to do a simple validation to have a syntactically correct e-mail address ... meaning somthing like the following:
think the easiest way should be a regEx ... that matches that ... there are a lot of examples all over the web ... it shouldn't be a problem to find some that you could use for that purpose ... something like - var foo = 'name.surname@host.domain';
-
-
// the following regEx returns:
-
// ["name.surname@host.domain", "name", ".", "surname", "@", "host", ".",
-
// "domain"] into var check
-
-
var check = foo.match(/(\w+)([.])(\w+)([@])(\w+)([.])(\w+)/);
-
-
// now you may do something with check ;)
hope that helps ...
he already has it validating the email address for syntax.
gits 5,390
Expert Mod 4TB
sure ... he has ... only: our top-level-domain may have 2-4 chars (i.e. info) ... but a regEx is a more common way and you may use the returned array for a lot of things ... if there is a need ... its only an example to show how you may better check such things ... and the shown regEx is not optimal ... i know that. have a look at:
http://www.quirksmode.org/js/mailcheck.html
that is much better ... and has a good explaination too. its really simple to check that way ... you need not to 'extra-check' for emptyness etc. ... was only a hint ... of course you needn't to do it that way ... but if someone is new to javascript you may show him the ways things could be done ... wouldn't you agree? ...
thank guy here my final solution i am happy to keep the email validation as is i have read the tutorial u recommend and try to implement it unsuccessful see below
Unsuccessful email val code - function emailvalidation(entered, alertbox)
-
{
-
var x = entered.value
-
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
-
if (filter.test(x)){return true;}
-
{else (alertbox) {alert(alertbox);} return false;}
-
}
-
-
final solution
-
-
function emailvalidation(entered, alertbox)
-
{
-
-
with (entered)
-
{
-
apos=value.indexOf("@");
-
dotpos=value.lastIndexOf(".");
-
lastpos=value.length-1;
-
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2)
-
{if (alertbox) {alert(alertbox);} return false;}
-
else {return true;}
-
}
-
}
-
-
-
-
-
-
-
-
-
///////////////////////
-
function emptyvalidation(entered, alertbox)
-
{
-
-
with (entered)
-
{
-
if (value==null || value=="")
-
{if (alertbox!="") {alert(alertbox);} return false;}
-
else {return true;}
-
}
-
}
-
//////////////////////////////
-
function emailval(entered, enteredtwo, alertbox)
-
{
-
-
if (entered.value != enteredtwo.value)
-
{if (alertbox) {alert(alertbox);} return false;}
-
else {return true;}
-
}
-
-
-
-
///////////////////////////////////
-
function formvalidation(thisform)
-
{
-
with (thisform)
-
{
-
if (emailval(email,emailtwo,"The two e-mail addresses do not match")==false) {emailtwo.focus(); email.focus(); return false;};
-
if (emailvalidation(email,"Your E-mail Address Is Not Valid")==false) {email.focus(); return false;};
-
if (emptyvalidation(name,"Please Enter Your Name")==false) {name.focus(); return false;};
-
if (emptyvalidation(message,"Please Enter Your Equiry")==false) {message.focus(); return false;};
-
if (emailvalidation(emailtwo,"Your E-mail Address Is Not Valid")==false) {emailtwo.focus(); return false;};
-
/////
-
-
-
/////
-
}
-
}
-
Thank again hope i can return the favour
gits 5,390
Expert Mod 4TB
you made an syntax-error - compare your code with the following that works :) -
function emailvalidation(entered, alertbox) {
-
var x = entered.value
-
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
-
-
if (filter.test(x)) {
-
return true;
-
} else {
-
if (typeof alertbox != 'undefined') {
-
alert(alertbox);
-
}
-
return false;
-
}
-
}
-
gits 5,390
Expert Mod 4TB
... and i had a look about it to finetune the code for beautiness & readability: -
function emailvalidation(entered, alertbox) {
-
var eva = entered.value;
-
var rex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
-
var val = re.test(eva);
-
-
if (!val && typeof alertbox != 'undefined') {
-
alert(alertbox);
-
}
-
-
return val;
-
}
-
note ... thats all to do ... you don't need to check for empty value until the rex didn't match in that case ... if you want to produce different errormessages you may extend the function with a check for eva != 0 or alternativly eva != '' and differ between unmatching and emptyness perhaps you want to use: -
// pass that to function emailvalidation
-
alertbox = {
-
empty: 'message_empty',
-
incorr: 'message_incorrect_syntax'
-
};
-
-
function emailvalidation(entered, alertbox) {
-
var eva = entered.value;
-
var rex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
-
var val = re.test(eva);
-
-
if (!val && typeof alertbox != 'undefined') {
-
alert(eva != 0 ? alertbox.incorr : alertbox.empty);
-
}
-
-
return val;
-
}
-
this is only an idea ... if your code is working ... use that if you pefer :) but have in mind: the above example has some advantages like less lines of code, one place to maintain all validationlogic, the rex to adapt for matching-purpose ... :) good luck ...
Wow :) thank again, just getting to grips with the javascript syntax and i have amended emailvalidation as per your example and what you know it work brilliantly
many thank!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sue |
last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided
to improve character checking on my project. In my project I only had
to do very basic validation. Therefore, I only had one...
|
by: GIMME |
last post by:
Background ...
I've created a web application that allows a user to create an
HTML application from IE.
The application itself creates an XML representation of a XHTML
form. The XHTML...
|
by: Madha K |
last post by:
I am developing a web application that need to support UTF-8
characters.
For client side validations, can javascript be used to handle UTF-8
characters.
1) How javascript can be used to restrict...
|
by: mhk |
last post by:
Hi,
Is there any way to create/set Session veriable in JavaScript.
Please let me know if anyone has an idea.
Thanks alot.
|
by: Allan M. |
last post by:
I have a series of select boxes that must be populated
client side, because they interact with each other. The
design specification calls for these boxes to be updated
without having to make a...
|
by: IkBenHet |
last post by:
Hello,
Currently I am using a large input form on a website that is based on
ASP and JavaScript.
Depending on the values that are filled in by the user the forms does a
refresh and makes...
|
by: |
last post by:
Hi all,
Has anyone been able to write some custom javascript on the onclick event of
submit button to do certain things like disable submit button, only submit
form once etc. This was a breeze...
|
by: daniel.boorn |
last post by:
Form validation using JavaScript has never been as easy and simple! We
have developed a free generic form validation script that can validate
any form with very little JavaScript required in form!...
|
by: Chris |
last post by:
Hi,
I have a form for uploading documents and inserting the data into a mysql
db. I would like to validate the form. I have tried a couple of Javascript
form validation functions, but it...
|
by: cbs7 |
last post by:
Hi all
I'm a complete newbie to web development and Javascript especially. I've been creating a form for a webpage and have used a validation script gen_validatorv2.js which I downloaded from the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |