javascript - Special character validation -


i have javascript written validate string alphanumeric wondering how add code include hyphens(-) , slash's(/) acceptable inputs. here current code:

function validateaddress() {   var address = document.getelementbyid('address');    if (address.value == "") {     alert("address must filled out");     return false;   } else if (document.getelementbyid('address').value.length > 150) {     alert("address cannot more 150 characters");     return false;   } else if (/[^a-za-z0-9\-\/]/.test(address)) {     alert('address can contain alphanumeric characters, hyphens(-) , slashs(\)');     return false;   } } 

simply add them character group. of course, because both - , / special characters in context (/ ends regexp, - expresses range), you'll need escape them preceding \:

function validateaddress(){     var tcode = document.getelementbyid('address').value;      if( /[^a-za-z0-9\-\/]/.test( tcode ) ) {         alert('input not alphanumeric');         return false;     }      return true;      } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -