+ Start a Discussion
Hiteshkumar Chaudhari 2Hiteshkumar Chaudhari 2 

how to restrict user to take numberic input in visualforce page??

how to restrict user to take numberic input in visualforce page??

i am using  : :" <h1>Amount</h1><apex:input type="number" id="damount" value="{!damount}"    /> " 

it gives error "Expected input type 'text', got 'number' for String data type"
Best Answer chosen by Hiteshkumar Chaudhari 2
sandeep reddy 37sandeep reddy 37
navin is right  
and one more is displaying custom error
use this coad

public class checknumericvalue {
    public string name{set;get;}
    public checknumericvalue(){
        
    }
    public void check(){
        if(name.isNumeric()==true){
            apexpages.addMessage(new ApexPages.message(apexpages.Severity.WARNING,'give only characters only'));
        }
    }
}


<apex:page controller="checknumericvalue" >
    <apex:form>
        <apex:messages />
    <apex:pageBlock title="check value">
        <apex:inputText value="{!name}" />
        </apex:pageBlock>
   <apex:commandButton value="check" action="{!check}" />
    </apex:form>
</apex:page>

but the best way is use java script 
I hope this workout for your requierment 
 

All Answers

sandeep reddy 37sandeep reddy 37
there is know way for that 
but using jqueryscript we achive it 
 
Hiteshkumar Chaudhari 2Hiteshkumar Chaudhari 2
how can  give me code of that ..??
can we append it to the viualforce page??
 
Navin SoniNavin Soni
<apex:input type="number" id="damount" value="{!damount}" onkeypress="return (event.charCode >= 48 && event.charCode <= 57);"/> 
sandeep reddy 37sandeep reddy 37
navin is right  
and one more is displaying custom error
use this coad

public class checknumericvalue {
    public string name{set;get;}
    public checknumericvalue(){
        
    }
    public void check(){
        if(name.isNumeric()==true){
            apexpages.addMessage(new ApexPages.message(apexpages.Severity.WARNING,'give only characters only'));
        }
    }
}


<apex:page controller="checknumericvalue" >
    <apex:form>
        <apex:messages />
    <apex:pageBlock title="check value">
        <apex:inputText value="{!name}" />
        </apex:pageBlock>
   <apex:commandButton value="check" action="{!check}" />
    </apex:form>
</apex:page>

but the best way is use java script 
I hope this workout for your requierment 
 
This was selected as the best answer