View Full Version : checking if a certain character has been entered.
blah-de-blah
August 28th, 2003, 01:49 AM
How would you check if a certain character has been entered in a form field? An example would be an e-mail form...I want to check if it has the '@' character. What command would you use? thanks
Btw, just give me the command and not the whole code for now so i can try it out myself :P
abzoid
August 28th, 2003, 02:02 AM
I cheat and use the Form Validation behavior by Yaromat. I don't bother trying to reinvent the wheel, and I HATE coding in Javascript. :}
Dreamweaver Extensions at www.yaromat.com
blah-de-blah
August 28th, 2003, 09:25 AM
Yeah that would be good for a last resort :P but i want to learn this so any other ideas?!
abzoid
August 28th, 2003, 09:59 AM
You'll want to do it client-side, before the form actually gets submitted to the server, so Javascript is the best way to go. You could do it server side, after submit, then return to the form if invalid, but that's clumsy for the user.
DigitalPimp is the resident Javascript whiz, when I checks in he should be able to at least point you in the right direction. I can code ASP script in my sleep, but I only know enough Javascript to be dangerous. =)
λ
August 28th, 2003, 10:39 AM
For checking whether there is an @ in a string with JS...
if(yourEmailString.indexOf("@") != 1){
//email is correct
processForm();
}else{
alert("That isn't a valid email adress.");
}
abzoid
August 28th, 2003, 10:43 AM
If you take the script that njs just posted (thank-you) and make it a function, you can then call it from an onSubmit command in the FORM tag.
blah-de-blah
August 28th, 2003, 10:51 AM
So should it be like this?
function validation() {
if(email.value.indexOf("@") != 1){
//email is correct
processForm();
}else{
alert("That isn't a valid email adress.");
}
}
Is processForm already a javascript function? I can't test it because my server thing is very slow :-\ Oh yea i changed 'youremailString' to 'email.value.indexOf' where email is the form name. Would that work? thanks
λ
August 28th, 2003, 11:03 AM
no... processForm was just a function which submitted the form.
Unfortunately I don't really know JavaScript. I just pulled that out of Flash AS.
Also, you don't need a server to test JavaScript. You can just open the pages in IE or Mozilla or whatever browser you use.
blah-de-blah
August 28th, 2003, 11:05 AM
Oh ok, well i'll try it. I have to upload it to a server because i use php for the mail form :-\ Thanks for the help though njs and abzoid
blah-de-blah
August 28th, 2003, 11:22 AM
I think i have found a good email validation code. But its pretty confusin :-\ I'll work on it though...thanks :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.