Help with Simple validation javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • whereswally007
    New Member
    • May 2010
    • 2

    Help with Simple validation javascript

    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

    Code:
    //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;
    }
    Last edited by Markus; May 10 '10, 12:23 PM. Reason: Added code tags, moving to javascript
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Whether the function is getting called? and in the html input box how you are calling the function chkAddress()?

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • whereswally007
      New Member
      • May 2010
      • 2

      #3
      calling isnt the problem because at the moment no matter what it just runs the alert but yes it cans run from the html from and excuted in a js file

      Comment

      Working...