0

i am using netbean to develop a registration form.
As this i want to know what is the coding to check input of text, integer, email , so i can restrict what they input..hope some 1 help me =)

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by dean8710
0

show what code you have for the input, so that the javascript demons can see what requirement of validation there is
else could write you 10000s of if() statements and none of them are appropriate

the answer probably won't come from me,
javascript -hopeless,
but somebody has the signature "half the solution is defining the problem"

0

Here are two functions for email and numbers. I don't know what you want to check for with text. If it's free form text there's really no check. Did you just want characters and no numbers?

<script>
function validate() {
	if (!isEmail(document.getElementById("emailAddr").value)) {
		alert("Bad email address");
		return;
	}
	if (!isNumeric(document.getElementById("myNumber").value, false)) {
	    alert("Bad number");
		return;
	}
	alert("Good Job!);
}
function isEmail(str) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)){
		return (true)
	}
	return (false)
}
function isNumeric(sText, decimalAllowed) {
    if (sText.length == 0) return false;
    var validChars = "";
	if (decimalAllowed) {
		validChars = "0123456789.";
	} else {
		validChars = "0123456789";
	}
    var isNumber = true;
    var charA;
	var decimalCount = 0;
    for (i = 0; i < sText.length && isNumber == true && decimalCount < 2; i++) {
		charA = sText.charAt(i); 
		if (charA == ".") { 
			decimalCount += 1;
		}
		if (validChars.indexOf(charA) == -1) {
			isNumber = false;
		}
	}
	return isNumber;
}
</script>
<form action="#" name="form1" id="form1" method="GET">
	E-mail Address:<br />
	<input type="text" name="emailAddr" id="emailAddr" /><br />
	Enter Number:<br />
	<input type="text" name="myNumber" id="myNumber" /><br />
	<input type="button" value="Submit" id="button" onClick="validate()" />
</form>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.