Find the below simple JavaScript code to allow only positive numbers in textbox. The below script done using javascript keyboard events. This will prevent users from entering other characters except numbers.
Example:
Example:
- <apex:page standardController="Account">
- <script type="text/javascript">
- function isNumber(evt)
- {
- evt = (evt) ? evt : window.event;
- var charCode = (evt.which) ? evt.which : evt.keyCode;
- if(charCode > 31 && (charCode < 48 || charCode > 57))
- {
- alert('Please enter positive number only');
- return false;
- }
- return true;
- }
- </script>
- <apex:form >
- <apex:pageBlock >
- <apex:pageBlockSection >
- <apex:inputField value="{!Account.Name}"/>
- <apex:inputField value="{!Account.AccountNumber}" onkeypress="return isNumber(event)"/>
- </apex:pageBlockSection>
- </apex:pageBlock>
- </apex:form>
- </apex:page>
Thanks to StackExchange
Reference: Keyboard events
No comments:
Post a Comment