HTML textfield whose values cannot be 0 using Javascript -


i trying make javascript function check if user entered value inside text field cannot less 9 digits & cannot 0s.

this made

function checkfield(field) { if (field.value.length <9 || field.value=="000000000") { alert("fail"); field.focus(); return false; } else  { return true; } }  <input type ="text" id="number1" onblur='return checkfield(this)'> 

but doesnt check condition user enters more 9 values , 0's. checks 1 condition exact 9 zeros 000000000

so, if understand right want user able enter number more 9 digits, cannot zeros, right?

this can done regexp:

var value; // obtain somehow  if (/^\d{9,}$/.test(value) && !/^0+$/.test(value)) {     // ok } 

what checks whether value @ lest 9 digits (it not allow digits) , not 0s.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -