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

Reading which Non-Character Key was pressed

1697


Create a ViewState Property?

2295


code to keep a page Out of the browser history

1663


code to create a new window

1756


function to combine two or more arrays

1709






how to create a Draggable element

1976


determine which Element received an Event

1909


write a code that user can choose/alter Body Text Size

1614


write a code to generate pseudorandom numbes

1793


Code to Block submission of form by pressing Enter Key

2089


How to block double clicks

1626


program to show a progress bar

2132


maximizing the main window

1643


code to sorting an array of objects

1997


how to get the User's Time of Day

1677