javascript - Regular expression on textarea -


i'm having bit of trouble validating form have, can check letters, numbers , full stop ("period") in single text input, can't life of me work @ on textarea field.

in validation have this:

var usernamecheck = /^[a-za-z0-9.]{5,1000}$/;  

the validation i've tried doesn't work on textarea ($itswusers) is:

if(!document.all.itswusers.value.match(usernamecheck))                 {                 alert ("please write usernames in correct format (with full stop between first , last name).");                 return false;                 } 

however, following on 'input type="text"' works fine on same form

if(!document.all.sfusersname1.value.match(usernamecheck))                 {                 alert("usernames can contain letters, numbers , full stops (no spaces).");                   return false;                   }   

i need validate usernames, 1 name per line e.g.

john.smith peter.jones1 

these both ok following wouldn't be:

john smith david.o'leary 3rd.username 

any help/pointers appreciated (i know basic html/php/javascript)

to validate line line, i'd use split function turn each line array. then, loop through array , run regex on each line. way, can report line invalid. this:

<textarea id="itswusers"></textarea> <button onclick="validate()">validate</button>  <script>   var usernamecheck = /^[a-za-z0-9]{5,1000}\.[a-za-z0-9]{5,1000}$/;    function validate()   {     var val = document.getelementbyid('itswusers').value;     var lines = val.split('\n');      for(var = 0; < lines.length; i++)     {       if(!lines[i].match(usernamecheck))       {         alert ('invalid input: ' + lines[i] + '.  please write usernames in correct format (with full stop between first , last name).');         return false;       }      }      window.alert('everything looks good!');   } </script> 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -