I am trying to Validate the user input in the VF Page. This custom field is a Text data type and the Maximum length is 6. In the VF Page I need to make sure this field entered is a numeric and cannot be less than/ more than 6 digits, tried the validation using the javascript like below but it is not throwing the error
<apex:inputField value="{!oppRec.Str__c}" required="true" onchange="checkStr();" >
<apex:actionSupport event="onchange" reRender="form" status="status"/>
</apex:inputField >
<div id="err1"></div>
<script type="text/javascript">
function checkStr(){
var phone=document.getElementById("j_id0:j_id2:j_id4:j_id31:j_id34:j_id35").value;
var letters = /^[A-Za-z]+$/;
if(phone.length!=6 || phone.match(letters))
document.getElementById("err1").innerHTML="Number must be 6 digits long. OR Can not contain Letters.";
}
</script>
I dont see any validation error throwing on the sreen when I enter characters in the filed or put the numbers less than 6 digits. Also is there a way I can show the error message inline with in the filed like how it shows for the Required field and all. Any help is greatly appreciated