validation code / function to allow only NUmbers in a text box

Answer Posted / shwetha kamath

function validate_user_editadvanced_form_username(element)
{var valid = "0123456789"
var ok = "yes";
var temp;
for (var i=0; i<element.value.length; i++) {
temp = "" + element.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
alert("Invalid entry! Only numbers are accepted!");
element.focus();
element.select();
}
}

Is This Answer Correct ?    9 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

code to sorting an array of objects

2171


Create a Menu that can be activated while clicking on Right Mouse button

1882


how to create Expandable and Collapsible Menus

2868


code to detect versions of different browsers like internet explorer, netscape, mozilla, opera etc

1913


how to convert between arrays and strings

2319


how to Scroll a DIV content

2339


write a code to generate pseudorandom numbes

2015


code to create a new window

1936


how to Auto Scroll the page

1801


create Drop-Down Navigation Menus

1885


snippet to prevent submission of form when certain/any validations got failed

1724


How to encode and decode URL strings?

1977


code to Hide and Show form controls

1991


How to block double clicks

1835


Create a ViewState Property?

2451