Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
193
rated 0 times [  199] [ 6]  / answers: 1 / hits: 8532  / 10 Years ago, fri, july 25, 2014, 12:00:00

How can I restrict entering special characters in the text box (txt_edition) by editing below code for validation? I want only numbers to be entered.



<script>
function validateForm()
{
var x = document.forms[frm_bokAdd][txt_edition].value;
if (x==null || x==)
{
alert(Edition must be filled out);
return false;
}
</script>


Below is my form



<form  name=frm_bokAdd action =#  method=post onsubmit=return validateForm() >
<table border=0 align=center>
<tr><td> <input type=text name=txt_edition ></td></tr>
<tr><td> <input type=submit name=bookIns_submit value=Add></td></tr>
</table>
</form>

More From » php

 Answers
3

How can I restrict entering special characters in the text box (txt_edition)




Don't. Allow users to arrive at a valid value any way they like, you really only care that the value is valid when it's sent to the server, and even then you should validate there too.




by editing below code for validation? I want only numbers to be entered.




Just test when the form is submitted, passing a reference to the form in the call:



<form ... onsubmit=return validateForm(this) >


and the function:



function validateForm(form) {
var value = form.txt_edition.value;

if (/D/.test(value) || value == '') {
alert(Edition must be filled out and contain only numbers);
return false;
}
}

[#43608] Thursday, July 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aileenreynap

Total Points: 140
Total Questions: 106
Total Answers: 99

Location: Andorra
Member since Sun, Oct 18, 2020
4 Years ago
;