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

javascript - Iterate over array and calculate average values of array-parts -

iphone - Using nested NSDictionary with Picker -

objective c - Newbie question -multiple parameters -