How to validate a string without Reg ex - Javascript -


im trying finish assignment; here's im stuck at:

user input can contain following allowed characters

  • alphabetic characters lower case (a-z) upper case (a-z)
  • apostrophe (‘)
  • hyphen (-)
  • must have @ least 1 alphabetic characters (a-z) (a-z)

note: cannot make use of reg ex.

i can't see way of doing without use of reg ex; here i've done far...

function validate_name() {    var name = document.getelementbyid("name").value;    name = name.trim();    (i = 0;i < name.lenght; i++) {       if (name.charat(i) == a...i don't know i'm doing 

you can that:

var str = prompt('enter input:'); var alphaexist = false; var valid = true; (var = 0; < str.length; i++) {     if ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'-".indexof(str.charat(i)) == -1) {         valid = false;     }     if ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz".indexof(str.charat(i)) > -1) {         alphaexist = true;     } } alert(valid && alphaexist ? 'valid' : 'invalid'); 

http://jsfiddle.net/4wwod65h/


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -