+ Start a Discussion
Mahesh MMahesh M 

How to write the fallowing code in Visualforcepage (Custom form Validation)?

Hi,

How to write  the fallowing code in Visualforcepage (Custom form Validation)?

<apex:page >
   <script>
   function InvalidMsg(textbox) {
       
       if (textbox.value == '') {
           textbox.setCustomValidity('Enter Email');
       }
       
       else if(textbox.validity.typeMismatch){
           textbox.setCustomValidity('please enter a valid email address');
       }
           else {
               textbox.setCustomValidity('');
           }
       
       return true;
   }
   function InvalidMsg1(textbox1) {
       
       if (textbox1.value == '') {
           textbox1.setCustomValidity('Enter Last Name');
       }
       
       
       else {
           textbox1.setCustomValidity('');
       }
       
       return true;
   }
   
   
   function InvalidMsgFirstName(textbox1) {
       
       if (textbox1.value == '') {
           textbox1.setCustomValidity('Enter First name');
       }
       
       
       else {
           textbox1.setCustomValidity('');
       }
       
       return true;
   }
   
   function InvalidMsgCompany(textbox1) {
       
       if (textbox1.value == '') {
           textbox1.setCustomValidity('Enter Company ');
       }
       
       
       else {
           textbox1.setCustomValidity('');
       }
       
       return true;
   }
   </script>
   <form id="myform">
       Email:     <input id="email" oninvalid="InvalidMsg(this);" name="email" oninput="InvalidMsg(this);"  type="email" required="required" /><br/><br/>
       FirstName: <input id="FirstName" oninvalid="InvalidMsgFirstName(this);" name="FirstName" oninput="InvalidMsgFirstName(this);"  type="text" required="required" /><br/><br/>
       Company:   <input id="Company" oninvalid="InvalidMsgCompany(this);" name="Company" oninput="InvalidMsgCompany(this);"  type="text" required="required" /><br/><br/>
       lastname:  <input id="lastname" oninvalid="InvalidMsg1(this);" name="lastname" oninput="InvalidMsg1(this);"  type="text" required="required" /><br/><br/>
       <input type="submit" />
   </form>

Thanks,
Sagar PareekSagar Pareek
Have checked out this post ?
https://developer.salesforce.com/forums/?id=906F000000095DwIAI

Hope this will solve your problem.
Mahesh MMahesh M
Thank you for your response Sagar Pareek