0
   

Help with Simple validation javascript

 
 
Reply Mon 10 May, 2010 09:35 pm
Ok below is my javascript code that gets activated when the used changed the input text box it doesnt work before what im searching is wrong can someone help me please. for address i need it so that it will allow the street number and then one or more words after and for the credit card type i need it to have one or more words with a space inbetween thanks

//event handler for address
function chkAddress() {
var myAddress = document.getElementById("inputtext5");

// Test the format of the input address
var pos = myAddress.value.search(/^\d+\s[A-Z][a-z]+/);
if (pos != 0) {
alert("The name you entered (" + myAddress.value + ") is not the correct form. \n" +
"The correct form is: 15 bogus street \n" +
"Please go back and fix your Address");
myAddress.focus();
myAddress.select();
return false;
} else
return true;
}

//event handler for creditcard
function chkCreditCardType() {
var myCreditCardType = document.getElementById("inputtext6");

// Test the format of the input credit card
var pos = myCreditCardType.value.search(/^w+( w+)?$/);
if (pos != 0) {
alert("The name you entered (" + myCreditCardType.value + ") is not the correct form. \n" +
"The correct form is: Master Card or Visa etc \n" +
"Please go back and fix your Credit card");
myCreditCardType.focus();
myCreditCardType.select();
return false;
} else
return true;
}
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 928 • Replies: 0
No top replies

 
 

Related Topics

 
  1. Forums
  2. » Help with Simple validation javascript
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 11/12/2024 at 06:26:25