function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Prem ChauhanPrem Chauhan 

syntax to accept only 10 digit number in inputText Field and should't contain any character please help me with this (Without Javascript)

syntax to accept only 10 digit number in inputText Field and should't contain any character please help me with this (Without Javascript)              
Khan AnasKhan Anas (Salesforce Developers) 
Hi Prem,

Greetings to you!

Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement. 

<apex:page controller="PhoneAccValC">
    <apex:messages />
    <apex:form >
        <apex:pageblock >
                <apex:inputField value="{!acc.Name}" />
                <apex:inputField value="{!acc.Phone}" />
                <apex:commandButton value="Validate Phone" action="{!validate}" />

public class PhoneAccValC {
    public Account acc {get;set;}
    public PhoneAccValC() {
        acc = [SELECT Id, Name, Phone FROM Account LIMIT 1];
    public PageReference validate() {
        if(Pattern.matches('[0-9]{10}', acc.Phone)) {
            UPDATE acc;
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Enter Valid Phone Number');
            return null;
        return null;

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Prem ChauhanPrem Chauhan
I am getting this error: Logical operator can only be applied to Boolean
Prem ChauhanPrem Chauhan
I have resolved the above error but still, it's not working. 
Ajay K DubediAjay K Dubedi
Hi Prem,
Try this code:
Component: CheckInptNumber
<aura:component >
    <aura:attribute name="EnterValue" type="Integer" />
    <lightning:input label=""  type="text" placeholder="Enter your 10-digit order number(eg:3751234531)" maxlength="10" onblur ="{!c.checkValue}" aura:id="enterNumber" pattern="[0-9]*"/>
    <div style="color: red;">
        <ui:outputText value="" aura:id="customeError" />
For Showing custome error you can use this:
    checkValue : function(component, event, helper) {
        var Number = component.find("enterNumber").get("v.value");
        console.log("-----" + Number);
        if( isNaN(Number) || Number.length != 10)
            component.find("customeError").set("v.value", "This cannot be null or text, You must enter number of 10 digits.");
            component.set("v.EnterValue", null);            
            component.find("customeError").set("v.value", " ");
            component.set("v.EnterValue", Number);

Application: CheckInptNumberApp
<aura:application >
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Ajay Dubedi
Prem ChauhanPrem Chauhan
Thanks, Ajay,

But it's not working, I didn't use the components in my code. My number field's data type is PHONE.