JavaScript Tutorial

R4R® JavaScript
(追記) (追記ここまで)
(追記) (追記ここまで)
Validation In Javascript

javascript provide a several type of validation and its also provide difference facilities in the validation forms The idea behind JavaScript form validation is to provide a method to check the user entered information before they can even submit it .

JavaScript also lets you display helpful alerts to inform the user what information they have entered by user that's correct or in correct .

form validation example :

Form validation is the process of checking that a form has been filled in correctly before it is processed.

<html>
<head> 
<script> 
 function validateform(){ 
 var name=document.myform.name.value; 
 var password=document.myform.password.value; 
 
 if (name==null || name==""){ 
 alert("Name can't be blank"); 
 return false; 
 }else if(password.length<10){ 
 alert("Password must be at least 10 characters long."); 
 return false; 
 } 
 } 
 </script> 
 <body> 
 <form name="myform" method="post" action=" " onsubmit=
	"return validateform()" > 
 Name: <input type="text" name="name"><br/> 
 Password: <input type="password" name="password"><br/> 
 <input type="submit" value="register"> 
 </form> 
</html>
</head> 

Output :

(追記) (追記ここまで)

Number Validation :

<html>
<head>
<script >
 function lengthRestriction(elem, min, max){
	var Input = elem.value;
	if(Input.length >= min && Input.length <= max){
		return true;
	}else{
		document.write (
		"Please enter between " +min+ " and " 
		
		+max+ " characters");
		
		return false;
	}
}
</script>
<form>
Username(10-50 
characters): <input type='text' id='prasun'
/>
<input type='button' 
	onclick="lengthRestriction(document.getElementById('prasun'), 10, 50)
	"value='button' />
</form>
</head>
</html>

Output :

Please enter between 10 and 50 characters

(追記) (追記ここまで)
Copyright ©2021-22 r4r.co.in, all rights reserved. Theguestspost.com
Sitemap
Career
Post comment
About us
Subscription
Unsubscription

AltStyle によって変換されたページ (->オリジナル) /