asp.net - Javascript to verify specific String from textbox -
asp.net - Javascript to verify specific String from textbox -
here textbox result looks like,
please add together next dns entries 144.68.238.87 name.domain 144.68.238.88 name.domain 144.68.238.89 name.domain
the goal validate name.domain
making sure user replace name.domain
server name on textbox before submit it. if user doesn't replace name.domain
server name, send alert message , homecoming false until user replace correctly.
here codes,
function domainvalidate() { var arrayoflines = document.getelementbyid('txt').value.split('/n'); arrayoflines.shift(); //use shift skip first line (i = 0; < arrayoflines.length; i++) { //somewhere here need split name.domain , verify var domainname = arrayoflines[i].split(" ", 2); if(domainname.equals("name.domain") { alert("you must replace name.domain new server name"); homecoming false; } } }
i not sure if these right since couldn't debug javascript.
first issue can see character newline incorrect. should \n
not /n
. sec issue see i
global variable, when should local. 3rd issue arrayoflines[i].split(' ', 2);
returns array, treating returns string on next line if (domainname.equals('name.domain')
.
with corrections code more this:
function domainvalidate() { var arrayoflines = document.getelementbyid('txt').value.split('\n'); arrayoflines.shift(); //use shift skip first line (var = 0; < arrayoflines.length; i++) { var line = arrayoflines[i].trim(); // grab sec part of split line, represents domain name var parts = line.split(' '); var domainname = parts[parts.length - 1]; if (!domainname || domainname === 'name.domain') { alert("you must replace name.domain new server name"); homecoming false; } } }
as far can tell without testing, should work expected. best way test though jsfiddle. add together html , script , phone call see if produces expected result.
javascript asp.net
Comments
Post a Comment