, 26 2011 . 04:04
+
, js .
FF, Opera, IE8 ( ).
, reg.php POST :
1. "" ( , , 2 )
2. "" ( , , "Backspace" , - 9 )
3. "E-mail" ( , )
4. "" ( , , 6 )
5. " " ( , "")
6. Checkbox " " ( )
7. "" ( , )
html :
<form name="form" action="reg.php" method="post">
*:<br/><input type="text" name="name" id="name"/><br/>
:<br/><input type="text" name="phone" id="phone"/><br/>
E-mail*:<br/><input type="text" name="email" id="email"/><br/>
*:<br/><input type="password" name="password" id="password"/><br/>
*:<br/><input type="password" name="password1" id="password1"/><br/>
<input type="checkbox" name="consent" id="consent"/> *<br/>
<input type="submit" value=""/>
</form>
"" form submit, valid_form
<form name="form" action="reg.php" method="post" onsubmit="return valid_form();">
...
"" , , valid_key_number
...
:<br/><input type="text" name="phone" id="phone" onkeypress="return valid_key_number(event);"/><br/>
...
C , javascript', .
valid_form, , valid, :
<script type="text/javascript">
function valid_form(){
valid=true;
...
return valid;
}
</script>
1.1 "" , .
if(document.getElementById("name").value==""){
alert(" ''.");
valid=false;
}
1.2 "" , .
if(document.getElementById("name").value.length<2){
alert(" .");
valid=false;
}
2. "" - ( valid_key_number).
if(document.getElementById("phone").value.length<9&&document.getElementById("phone").value!=""){
alert(" .");
valid=false;
}
3.1. "E-mail" - .
if(document.getElementById("email").value==""){
alert(" 'E-mail'.");
valid=false;
}
3.2. E-mail , email .
if(document.getElementById("email").value.match(/^\w+(['\.\-\+]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/)==null){
alert(" E-mail .");
valid=false;
}
4.1 "" - .
if(document.getElementById("password").value==""){
alert(" ''.");
valid=false;
}
4.2 "" , .
if(document.getElementById("password").value.length<6){
alert(" .");
valid=false;
}
5.1 " " - .
if(document.getElementById("password1").value==""){
alert(" ' '.");
valid=false;
}
5.1 "" " ".
if(document.getElementById("password").value!=document.getElementById("password1").value){
alert(" '' ' ' .");
valid=false;
}
6 " " - .
if(document.getElementById("consent").checked==false){
alert(" .");
valid=false;
}
valid_form.
<script type="text/javascript">
function valid_form(){
valid=true;
if(document.getElementById("name").value==""){
alert(" ''.");
valid=false;
}else{
if(document.getElementById("name").value.length<2){
alert(" .");
valid=false;
}else{
if(document.getElementById("phone").value.length<9&&document.getElementById("phone").value!=""){
alert(" .");
valid=false;
}else{
if(document.getElementById("email").value==""){
alert(" 'E-mail'.");
valid=false;
}else{
if(document.getElementById("email").value.match(/^\w+(['\.\-\+]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/)==null){
alert(" E-mail .");
valid=false;
}else{
if(document.getElementById("password").value==""){
alert(" ''.");
valid=false;
}else{
if(document.getElementById("password").value.length<6){
alert(" .");
valid=false;
}else{
if(document.getElementById("password1").value==""){
alert(" ' '.");
valid=false;
}else{
if(document.getElementById("password").value!=document.getElementById("password1").value){
alert(" '' ' ' .");
valid=false;
}else{
if(document.getElementById("consent").checked==false){
alert(" .");
valid=false;
}
}
}
}
}
}
}
}
}
}
return valid;
}
</script>
valid_key_number, "" ( 48 57) Backspace ( - 8).
function valid_key_number(e){
e = (e) ? e : window.e;
w = (e.keyCode) ? e.keyCode : e.which;
if((w<48||w>57)&&w!=8) return false;
}
, .
<script type="text/javascript">
function valid_form(){
valid=true;
if(document.getElementById("name").value==""){
alert(" ''.");
valid=false;
}else{
if(document.getElementById("name").value.length<2){
alert(" .");
valid=false;
}else{
if(document.getElementById("phone").value.length<9&&document.getElementById("phone").value!=""){
alert(" .");
valid=false;
}else{
if(document.getElementById("email").value==""){
alert(" 'E-mail'.");
valid=false;
}else{
if(document.getElementById("email").value.match(/^\w+(['\.\-\+]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/)==null){
alert(" E-mail .");
valid=false;
}else{
if(document.getElementById("password").value==""){
alert(" ''.");
valid=false;
}else{
if(document.getElementById("password").value.length<6){
alert(" .");
valid=false;
}else{
if(document.getElementById("password1").value==""){
alert(" ' '.");
valid=false;
}else{
if(document.getElementById("password").value!=document.getElementById("password1").value){
alert(" '' ' ' .");
valid=false;
}else{
if(document.getElementById("consent").checked==false){
alert(" .");
valid=false;
}
}
}
}
}
}
}
}
}
}
return valid;
}
function valid_key_number(e){
e = (e) ? e : window.e;
w = (e.keyCode) ? e.keyCode : e.which;
if((w<48||w>57)&&w!=8) return false;
}
</script>
<form name="form" action="reg.php" method="post" onsubmit="return valid_form();">
*:<br/><input type="text" name="name" id="name"/><br/>
:<br/><input type="text" name="phone" id="phone" onkeypress="return valid_key_number(event);"/><br/>
E-mail*:<br/><input type="text" name="email" id="email"/><br/>
*:<br/><input type="password" name="password" id="password"/><br/>
*:<br/><input type="password" name="password1" id="password1"/><br/>
<input type="checkbox" name="consent" id="consent"/> *<br/>
<input type="submit" value=""/>
</form>
.
.
.
:
html
javascript
html
email
onkeypress
onsubmit