+ Start a Discussion
Mahesh MMahesh M 

Can you help me  how to write custom  Form validation using  "setCustomValidity" (Jquery or Javascript)

Hi
Can you help me  how to write custom  Form validation using  "setCustomValidity" (Jquery or Javascript).
for Examle if the field value(Name) is empty when click submit button it should be  disply on Name field  " please enter the Name " ..

Thanks,
hitesh90hitesh90
Hello Mahesh,

See below sample code for how to write custom  Form validation using JavaScript.

Visualforce Page:
<apex:page id="page">
    <script>
        function customValidation(){
            if(document.getElementById('{!$Component.frm:txtName}').value == ''){
                alert('please enter the Name');
                return false;
            }
        }
    </script>
    <apex:form id="frm">
        <apex:inputText id="txtName"/>
        <apex:commandButton value="Check for Name" onclick="return customValidation();"/>
    </apex:form>
</apex:page>
Let me know if you have any question on this. Please mark this "Solved" if it helps.

Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/