本文介绍了我如何在Jquer中为名字赋予条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在该名字和姓氏中该字段应该只带字母,如果我写数字和字符串它应该显示错误。

dob当我进入april-01-2000年龄时将是15年,当我写30时,它应该显示错误。

在城市,州也应该是字母表。如果我写数字和字符串它应该显示错误。

和我文件附件。它应该只附加像doc这样的文件..没有图像如果图像被附加它应该显示错误。



我的代码是这样的。它的工作但我想在我的代码中有上述条件。

请帮我解决这些问题。



希望我能从你那里得到解决方案。等待你的回复。



in that first and last name the field should take only alphabets, if i write number and strings it should show error.
in dob when i enter april-01-2000 age will be 15 year, when i write 30 it should show error.
in city, state also should be in alphabets. if i write number and strings it should show error.
and i file attachment . it should attach only file like doc.. no image if image is attached it should show error.

My code is like this. its working but i want above conditions in my code.
Please help me to sort these problems.

hope i get solution from u. waiting for ur reply.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Job Form</title>
 <!-- Load jQuery and the validate plugin -->
  <script src="//code.jquery.com/jquery-1.9.1.js"></script>
  <script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
  
  <!-- jQuery Form Validation code -->
  <script>
  
  // When the browser is ready...
  $(function() {
  
    // Setup form validation on the #register-form element
    $("#register-form").validate({
    
        // Specify the validation rules
        rules: {
            fname: {
			    required: true,
				digits: false,
				minlength: 10
			},	
            lname: {
			    required: true,
				alphabets: true,
				minlength: 10
			},	
            birth_month: "required",
			birth_date: "required",
            birth_year: "required",
   			age: "required",
            gender: "required",
            address: "required",
			city: "required",
            state: {
			    required: true,
				alphabets: true,
				minlength: 20
			},	
        	cellnumber: {
			    required: true,
				digits: true,
				minlength: 10,
			},	
			qual: "required",
			services: "required",
			texp: "required",
			expd: "required",
			services1: "required",
            ctc: "required",
            etc: "required",
			attachment: "required",
            email: {
                required: true,
                email: true
            },
            pincode: {
                required: true,
				digits: true,
                minlength: 6
				
            }
        },
        
        // Specify the validation error messages
        messages: {
            fname:{required : "Please Enter your first name",
			alphabets: "Please Enter only Letters",
			},
            lname: "please enter your last name",
            birth_month: "please specify your month of birth",
			birth_date: "please specify your date of birth",
            birth_year: "please specify your year of birth",
   			age: "please specify your age",
            gender: "please specify your gender",
            address: "please specify your address",
			city: "please specify your city in alphabets",
            state: "please specify your state in alphabets",
        	cellnumber: "please specify only numbers",
            qual: "please specify your Qualification",
			services: "please select the position",
			texp: "please specify your totla exp.",
			expd: "please specify your relevant exp.",
			services1: "please specify relocate",
            ctc: "please specify your ctc",
            etc: "please specify your expected ctc",
			attachment: "please attach resume",
            email:"please specify your email address",
            pincode: {
                required:"please specify your pincode ",
                minlength: "minlength will be 6 characters",
				maxlength: "maxlength will be 6 characters",
            }
        },
        
        submitHandler: function(form) {
            form.submit_button();
        }
    });

  });
  
  </script>
</head>
<body>
$fname = '';
$lname = '';
$age = '';
$birth_month = ''; 
$birth_day = '';
$birth_year = '';
$gender = '';
$address = '';
$city = '';
$state = '';
$pincode = '';
$cellnumber = '';
$email = '';
$qual = '';
$services = '';
$texp = '';
$expd = '';
$services1 = '';
$ctc = '';
$etc = '';
$attachment = '';
$output = '';
if (isset($_POST['submit_button'])) 
{
      $birth_month = trim($_POST["birth_month"]);
	  $birth_day = trim($_POST["birth_day"]);
	  $birth_year = trim($_POST["birth_year"]);
	  $dob=$birth_day."/".$birth_month."/".$birth_year; 
      $fname = trim($_POST["fname"]);
      $lname = trim($_POST["lname"]);
      	 // $dob=$birth_year.$birth_day. $birth_month; 
      $age = trim($_POST["age"]);
      $gender = trim($_POST["gender"]);
      $address = trim($_POST["address"]);
      $city = trim($_POST["city"]);
      $state = trim($_POST["state"]);
      $pincode = trim($_POST["pincode"]);
      $cellnumber = trim($_POST["cellnumber"]);
      $email = trim($_POST["email"]);
      $qual = trim($_POST["qual"]);
      $services = trim($_POST["services"]);
      $texp = trim($_POST["texp"]);
      $expd = trim($_POST["expd"]);
      $services1 = trim($_POST["services1"]);
      $ctc = trim($_POST["ctc"]);
      $etc = trim($_POST["etc"]);
      $attachment = trim($_POST["attachment"]);
	  
	   $errors = array();
	   
  if (strlen($fname) == 0)
      array_push($errors, "Please enter your name");
	
  if (strlen($lname) == 0)
    array_push($errors, "Please enter your Last name");
	
 if (strlen($age) == 0)
    array_push($errors, "Please enter your age");	

  if (!(strcmp($gender, "Male") || strcmp($gender, "Female"))) 
    array_push($errors, "Please specify your gender");
  
  if (strlen($address) == 0) 
    array_push($errors, "Please specify your address");
 
  if (strlen($city) == 0)
    array_push($errors, "Please enter your city");	

  if (strlen($state) == 0)
    array_push($errors, "Please enter your state");

  if (strlen($pincode) == 0)
    array_push($errors, "Please enter your pincode");	

  if (strlen($cellnumber) == 0)
    array_push($errors, "please specify only numbers no alphabets");

   if (strlen($qual) == 0)
    array_push($errors, "Please enter your Qualification");	
	
   if (strlen($services) == 0)
    array_push($errors, "Please enter your required position");
	
   if (strlen($texp) == 0)
    array_push($errors, "Please enter your total experience");	
	
   if (strlen($services1) == 0)
    array_push($errors, "Please enter required relocation");	
	
  if (strlen($ctc) == 0)
    array_push($errors, "Please enter your ctc");
	
  if (strlen($etc ) == 0)
    array_push($errors, "Please enter your expected ctc");
	
  if (strlen($attachment) == 0)
    array_push($errors, "Please attach Resume");
	
  if (strlen($expd) == 0)
    array_push($errors, "Please enter your relevant experience");
    
  if (!filter_var($email, FILTER_VALIDATE_EMAIL))
    array_push($errors, "Please specify a valid email address");

// If no errors were found, proceed with storing the user input
  if (count($errors) == 0) {
    array_push($errors, "No errors were found. Thanks!");
  }

  //Prepare errors for output
  $output = '';
  foreach($errors as $val) {
    $output .= "<p class="output">$val</p>";
  }
  
$conn = mysql_connect("localhost","root","password");
mysql_select_db("employees") or die( "<p><span style="\"color:" mode="hold" />$sql="INSERT INTO appform (fname, lname, dob, age, gender, address, city, state, pincode, cellnumber, email, qual, services, texp, expd, services1, ctc, etc, attachment) VALUES ('$fname', '$lname', '$dob', '$age', '$gender', '$address', '$city', '$state', '$pincode', '$cellnumber', '$email', '$qual', '$services', '$texp', '$expd', '$services1', '$ctc', '$etc', '$attachment')";
$result= mysql_query($sql);
mysql_close($conn);
//confirm
echo "<p><span style="\"color:" mode="hold" /> } 
?>
  <form id="register-form" method="post" onClick="Submit()" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);??>">
<table border="1">
	  <tr>
	    <td align="center">Online Job Application Form</td>
	  </tr>
	  <tr>
	     <td>
	      <table>
          <tr>
	          <td>First Name</td>
	          <td><input type="text" name="fname" value="">
                </td>
	        </tr>
		<tr>
	          <td>Last Name</td> 
	          <td><input type="text" name="lname" value="">
                   </td> </tr></table></td>
	        </tr>
		<tr>
            <td width="49%"> Date of Birth</td>
            <td height="3" colspan="3">
            <select name="birth_month">
	    <option>none</option>
            <option selected value=1>January
            <option value=2> February
            <option value=3>March
            <option value=4>April
            <option value=5>May
            <option value=6>June
            <option value=7>July
            <option value=8>August
            <option value=9>September
            <option value=10>October
            <option value=11>November
            <option value=12>December 
            </select>
            <select name="birth_day">
	    <option>00</option>
            <option selected value=1>01
            <option value=2>02
            <option value=3>03
            <option value=4>04
            <option value=5>05
            <option value=6>06
            <option value=7>07
            <option value=8>08
            <option value=9>09
            <option value=10>10
            <option value=11>11
            <option value=12>12
            <option value=13>13
            <option value=14>14
            <option value=15>15
            <option value=16>16
            <option value=17>17
            <option value=18>18
            <option value=19>19
            <option value=20>20
            <option value=21>21
            <option value=22>22
            <option value=23>23
            <option value=24>24
            <option value=25>25
            <option value=26>26
            <option value=27>27
            <option value=28>28
            <option value=29>29
            <option value=30>30
            <option value=31>31</option>
          </select>
		  <select name="birth_year">
	    <option>0000</option>
            <option selected value=1980>1980
			<option value=1981>1981
			<option value=1982>1982
			<option value=1983>1983
            <option value=1984>1984
            <option value=1985>1985
            <option value=1986>1986
            <option value=1987>1987
            <option value=1988>1988
            <option value=1999>1999
            <option value=2000>2000
            <option value=2001>2001
            <option value=2002>2002
            <option value=2003>2003
            <option value=2004>2004
            <option value=2005>2005
            <option value=2006>2006
            <option value=2007>2007
            <option value=2008>2008
            <option value=2009>2009
            <option value=2010>2010
            <option value=2011>2011
            <option value=2012>2012
            <option value=2013>2013
            <option value=2014>2014</option>
          </select>
		  </td>
           </tr>
			
	    <tr>
	       <td>Age</td>
               <td><input type="text" name="age" value="">
                </td>
	    </tr>
	    <tr>
		<td>Gender</td>
                <td><label class="radio">
                <input type="radio" name="gender" id="optionsRadios1" value="Male" checked>
                 Male
                </label>
                <label class="radio"> 
                <input type="radio" name="gender" id="optionsRadios2" value="Female">
                 Female
                 </label>
			</td>
		    </tr>	
		<tr>
	           <td>Address</td>
	           <td><input type="text" name="address" value="">
                </td>                                
		</tr>
		<tr>
	           <td>City</td>
	           <td><input type="text" name="city" value="">
                 </td>
	        </tr>
		<tr>
	           <td>State</td>
	           <td><input type="text" name="state" value="" >
                   </td>
	        </tr>
		<tr>
	           <td>Pincode</td>
	           <td><input type="text" name="pincode" value="">
                  </td>
	        </tr>
		<tr>
	           <td>Cell Number</td>
	           <td><input type="text" name="cellnumber" value="">
               
			  </td>
	        </tr>
		<tr>
	           <td>Email Address</td>
	           <td><input type="text" name="email" value="">
                </td>
	        </tr>
		<tr>
		    <td>Qualification</td>
		    <td><input type="text" name="qual" value="">
		   </td>
		</tr>
		<tr>
		   <td>Applying for the position of</td> 
		   <td><select name="services" id="Department" class="Department">
                   <option selected="selected">none</option>
                   <option id="Popup" value="PHP Developer (Zend Framework)">PHP Developer (Zend Framework)</option>
                   <option value="PHP Developer (ScriptCase)">PHP Developer (ScriptCase)</option>
                   <option value="Admin/ Office Asstt.">Admin/ Office Asstt.</option>
		   <option value="Business Development Manager">Business Development Manager</option>
		   <option value="Sales Executive">Sales Executive</option>
		   <option value="Marketing Trainee">Marketing Trainee</option>
		   <option value="Back Office (voice)">Back Office (voice)</option>
		   <option value="Receptionist">Receptionist</option>                               		     </td>
		 </tr>
		  <tr>
		      <td>Total Exp</td>
		      <td><input type="text" name="texp" value=""> 
                   </td>
		 </tr>
		 <tr>
	             <td>Experience detail</td>
	             <td><input type="text" name="expd" value="">
                   </td>
	         </tr>
		 <tr>
		     <td>willing to relocate</td>
		     <td><select name="services1">
                     <option selected="">none</option>
                     <option id="Popup" value="Yes">Yes</option>
                     <option value="NO">No</option>                                                            </td>
                 </tr>	
                 <tr>
            <td>Current Salary</td>
                <td><input type="text" name="ctc" value="">
				</td>
            </tr>
            <tr>
            <td>Expected Salary</td>
                <td><input type="text" name="etc" value="">
				</td>
            </tr>
	    <tr>
		<td>Upload your Resume</td>
	        <td><input type="file" name="attachment" value=""></td> 
	    </tr>
	    <td></td>
	             <td align="right"><input type="submit" name="submit_button" value="Submit"> 
				 </td>
		     <td align="left"><input type="reset" name="reset" value="Reset">  </td>
			
	    
	 
	        </table>
	      
      
    
	</form>
  </body>
</html></p></p>

推荐答案




这篇关于我如何在Jquer中为名字赋予条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 12:27