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
sra gowthamsra gowtham 

Validate the Account Number is numeric if not blank?

 i want this validation code
Naveen DhanarajNaveen Dhanaraj
Try This,
AND(
    NOT(ISNUMBER(AccountNumber)),
    ISBLANK( AccountNumber )
)

 
sra gowthamsra gowtham
plzz give me explanation naveen
Naveen DhanarajNaveen Dhanaraj
NOT(ISNUMBER(AccountNumber)) - Which means only Numeric can be entered because datatype of AccountNumber is Text.
ISBLANK( AccountNumber )---
If the Account number field is blank

This will throw error or trigger validation rule when AccountNumber is Text and If the Account number field is blank .
 
sra gowthamsra gowtham
after i applied this code i jst checked by entering some random alpha numeric like xyz12 it saves and not giving any error.why
Akshay_DhimanAkshay_Dhiman
Hi Sra,

Please try this:
AND(
   ISBLANK(AccountNumber),
   NOT(ISNUMBER(AccountNumber))
)

Thanks
Akshay
sra gowthamsra gowtham
Hai Akshay,
after i applied this code i jst checked by entering some random alpha numeric like xyz12 it saves and not giving any error.why
Naveen DhanarajNaveen Dhanaraj
Check Your validation Rule is active or not...
SFDC Beginner745SFDC Beginner745
Hi Gowtham,

By default the Account Name field is Mandatory and you cannot left is as a blank.

Thanks
Developer Forum
Akshay_DhimanAkshay_Dhiman
Hi Sra,

NOT(ISNUMBER(AccountNumber))

User-added image

Thanks
Akshay
sra gowthamsra gowtham
thank you akshay.. and small doubt i have requirement if i leave a field as blank and save it so that i need a message as no field enter and at the same time if i enter alpha numeric number i need a message as its not alphanumeric..can we do it in one validatation
sra gowthamsra gowtham
thanks naveen
Akshay_DhimanAkshay_Dhiman

Sra,

No, It's not possible, if you want to display more than one errors then you can use more than one validation rules.
The problem will be solved.

sra gowthamsra gowtham
Akshay
can we slove it by using triggers 
Ajay K DubediAjay K Dubedi
Hi Sra,

Your problem has solved through trigger.
1-If your Account number is empty then account created.
2-If you enter Account Number is string then Account not create and through error.
3-If you update Account Number and try to insert string then through error.
User-added image
User-added image

trigger AccountNumberMustIntegerType on Account (before insert,before update) {
    for(Account ac:Trigger.New){
        if(ac.AccountNumber!=Null){
            if(ac.AccountNumber.isNumeric()){
                ac.AccountNumber=ac.AccountNumber;
            }
            else{
                ac.AccountNumber.addError('Field must be integer type');
            }
        }
    }
}

Please let me know if you have any query.

Please mark it as best Answer if you find it helpful.

Thank You
Ajay Dubedi
Akshay_DhimanAkshay_Dhiman
Hi Sra,

Yes, we can please try the below code:
 
//Helper Class
public class AccountNotEmpty {
    public static void isAccount(List<Account> accList){
        for(Account ac: accList){
            if(ac.AccountNumber == Null){
                ac.AccountNumber.addError('Field is not be Empty');
            }
            else if(ac.AccountNumber.isNumeric()){
                ac.AccountNumber=ac.AccountNumber;
            }
            else{
                ac.AccountNumber.addError('Field must be integer type');
            }
        }
    }
}

//Tregger Class
trigger AccountNumberNotEmpty on Account (before insert,before update) {
    if(trigger.isBefore){
        AccountNotEmpty.isAccount(trigger.new);
    }

}

Thanks
Akshay

 
sivanaveen tummalacharlasivanaveen tummalacharla
OR(
ISBLANK( account_number__c ),
NOT( ISNUMBER( account_number__c))
)
    


IT SHOULD NOT BE NUMERTIC AND IT SHOULD NOT BE IT WORKS TRY THIS
 
SophiaSophia
Try with OR instead of AND , this will ensure that both conditions are checked. I tried for SSN field, it works.
OR(
ISBLANK( SSN__c ),
NOT(ISNUMBER( SSN__c ))
)
SophiaSophia
OR will ensure that the Error message is thrown even if one of the condition fails. AND will work only if both the conditions satisfy.