Monday, April 3, 2017

How To Allow Only Numbers in Phone Number Field in Visual Force Page

If your trying to restrict your phone number field to accept only Numbers in visual force page you can use the below simple JavaScript code to achieve this easily.

Java Script Code:
<script>

function isNumber(evt) {
        evt = (evt) ? evt : window.event;
        var charCode = (evt.which) ? evt.which : evt.keyCode;
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            return false;
        }
}

</script>

<apex:inputfield value="{!c.Phone__c}" id="boPhone" onkeypress="return isNumber(event)"/>



Thanks for visiting..hope this helps you!

Tuesday, March 28, 2017

How To Check Whether at Least One Check Box Checked or Not? Using JQuery

If you want to know whether at least one check box is checked or not in visual force it's very easy using Jquery .Please use the below code snippet to check this functionality.

Sample Source Code:


function selectionCheck(selClass)
   {
          
        var chbxClass = '.'+selClass; // selClass is styleclass name for all your checkbox
          
        if($(chbxClass).is(':checked'))
  {
   alert('You have selected one or more records');
  }
                
        else
        {
            alert('Please select at least one record');
            return false;
        }
  }


In the above code if you see we are one jQuery method called is() ,this method will loop through the all the list and returns true if at least one record has checked among the list otherwise it will return false.


Thanks for visiting..hope this helps you!