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 =)

Recommended Answers

All 3 Replies

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"

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>

Missed:

11.	alert("Good Job!");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.