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

how to pass data between pages using Cookies

1850


function to combine two or more arrays

1703


Reading which Non-Character Key was pressed

1690


how to create a Custom Scrollbar

2050


program to show a progress bar

2126






code to positioning of window in certain dimensions

1666


how to create a Draggable element

1968


code to detect availability of cookies

1786


How to block double clicks

1622


code to get the coordinates of a Click Event

1741


how to Auto Scroll the page

1633


how to create an anonymous function

1732


how to transform XML Data into HTML

1900


code to set the main window's size

1708


sample code to auto focusing the first field in a form

2033