Need JavaScrpt Code

Any problem with javascript can be discussed here.
Locked
znad
Posts: 250
Joined: Sat Oct 01, 2005 3:12 pm

Need JavaScrpt Code

Post by znad »

Hi All
People I now nothing about java scripts, and i need i code imediatly..
I am looking for a code to check the text box, if its entry wasn't in an e-mail form, then an action will hapen tells the user thats its an error..

Can you help me with this?
Need JavaScrpt Code.txt


kaos_frack
Posts: 504
Joined: Sat May 07, 2005 8:03 am
Contact:

Re: Need JavaScrpt Code

Post by kaos_frack »

znad wrote:Hi All
People I now nothing about java scripts, and i need i code imediatly..
I am looking for a code to check the text box, if its entry wasn't in an e-mail form, then an action will hapen tells the user thats its an error..

Can you help me with this?
Need JavaScrpt Code.txt
ok i can help you
assuming that you named that textbox as 'userEmail'
and assuming that your form is name 'myForm'
here's the code"

// creating a shorthand
function CheckEmail(){
var Email = ****.myForm.userEmail]{6,}@[a-z0-9-]+\.[a-z0-9]+$/i)){
alert("Invalid email address");return false;
return true;
}

good luck with your site
Mizo

Post by Mizo »

thank you ya kaos_frack about this info
kaos_frack
Posts: 504
Joined: Sat May 07, 2005 8:03 am
Contact:

Post by kaos_frack »

oh sorry i've made a little mistake
i've omitted one curle brace
it should be:
function CheckEmail()
{
var Email = ****.myForm.userEmail;
if(Email.value.search(/^[a-z0-9]{6,}@[a-z0-9-]+\.[a-z0-9]+$/i)){
alert("Invalid email address");return false;}
return true;
}
mohumben
Posts: 82
Joined: Thu Sep 15, 2005 9:45 pm

Post by mohumben »

Oh, there's another way of retrieving the textbox value, instead of ****.myForm.userEmail you can use ****.getElementById('email') (provided you defined the attribute id), I think it's easier.

Obviously this would be useless if it the form doesn't checks it. Code rewrote with slighty modifications:

Code: Select all

function checkEmail()
{ 
  var email = ****.getElementById('email'); 
  if (email.value.search(/^[a-z0-9]{6,}@[a-z0-9-]+\.[a-z0-9]+$/i)) {  
    alert("Invalid email address");
    email.focus();
    return false; 
  } else { 
    return true; 
  } 
}
Form:

Code: Select all

<form onsubmit="return checkEmail();">
Email: <input type="text" id="email" name="userEmail">
<input type="submit" value="Send">
</form>

Code: Select all

define('I_LOVE_PHP', true);
Holograph
Posts: 14
Joined: Wed Oct 11, 2006 7:52 am

Post by Holograph »

I gotta learn JS some day Lol. It seems so fun
hacker
Posts: 20
Joined: Wed Oct 25, 2006 11:46 pm

Post by hacker »

why dont people try google once in a while?
Locked