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
Kr ramKr ram 

Help with--- Set a validation rule in a text field so that only numbers are allowed

Contract id is a text field but i wanted to accept only numbers only 11 digits allowed,i do NOT want to change the field type but the below validation rule solution works ,but how do i restrict so that it accepts only 11 digits,any other thoughts appreciated as well.. thanks

 

NOT(ISNUMBER( Contract_ID ))

Best Answer chosen by Admin (Salesforce Developers) 
Kr ramKr ram

ok i think i needed up 11 digits used >11 tor text-.>number ,thanks.

All Answers

rohitrrohitr

Use the below one along with yours.

IF(LEN(Contract_ID) <> 11, FALSE,TRUE)

phiberoptikphiberoptik
OR(
NOT(ISNUMBER( Contract_ID )),
LEN(Contract_ID) <> 11
)

If the value is not a number or has any other number of characters than 11, this validation will trigger.
Kr ramKr ram

ok i think i needed up 11 digits used >11 tor text-.>number ,thanks.

This was selected as the best answer
phiberoptikphiberoptik

Sorry, Im not sure what you are trying to say. Do you mean you need "up to but no more than" 11 characters? So the number could be 9 characters or 10 or 5 or 11 but NOT 12 or more?

Kr ramKr ram

Ok with this validation rule 

 

NOT(ISNUMBER(contract id)) ||
AND(ISNUMBER(contract id), LEN(contract id) >11)

 

i want to allow blanks,meaning i want to save the record with a value in this field

any thoughts?

 

note contract id is a text field with length 88 ,

phiberoptikphiberoptik

"i want to allow blanks,meaning i want to save the record with a value in this field

any thoughts?"

 

This is a contradicting statement. Do you want to save blanks or values?

 

Also

 

NOT(ISNUMBER(contract id)) ||
AND(ISNUMBER(contract id)

 

contradict each other also.

 

Can you please state clearly what you want this validation rule to do?

Kr ramKr ram

Ok i want this field currently a text  field to do 2 things

 

1)accept only numbers upto 11 digits AND

2)accept blank values 

 

currently i cannot save the record without a value

Kr ramKr ram

This is what i did to solve the above problem

used the validation rule NOT(ISNUMBER(contract id)) || 
LEN(contract id) >10

 

and used the workflow rule to update whenever this field is saved blank .

phiberoptikphiberoptik

NOT(ISNUMBER(contract id)) || 
LEN(contract id) >10

 

Does not do what you said in your second to last post that you want.

 

Please verify if all of these are true:

 

1. Contract ID can be saved blank

2. Contract ID can be a number up to but no more than 11 characters long

3. Contract ID can be a string of text with no limit of characters (up to the 88 character field max)

Kr ramKr ram

Hi there

NOT(ISNUMBER(contract id)) || 
LEN(contract id) >10

 

Does not do what you said in your second to last post that you want.

 

Please verify if all of these are true:

 

1. Contract ID can be saved blank

2. Contract ID can be a number up to but no more than 11 characters long

3. Contract ID can be a string of text with no limit of characters (up to the 88 character field max)

----------------------------------------------------------------------------------------------------------------------------------------

For the above question only #2 is satisfied with this validation rule ,# 3 is the Current field type Contract ID is TEXT(88) field type ,so # 3 is no longer required ,i hope this helps.

phiberoptikphiberoptik
What I am asking you is if what you WANT is for all three to be true? Do you want this validation rule to allow all three points? Yes or No?
Kr ramKr ram

Hi ,IF # 1 and # 2 rule is satisfied i am OK ,# 3 is NO longer required.

phiberoptikphiberoptik

AND(

          NOT(ISBLANK(Contract_Id__c),

          OR(

                  NOT(ISNUMBER(Contract_Id__c),                 

                  LEN(contract id) >11

          )
)

 

This should throw an error if the field has a value and the value is not a number OR if the field has a value and the value is a number with more than 11 characters. Blank values will not throw an error.

 

Please test and confirm.

 

 

Laxita NouhvarLaxita Nouhvar
1) Room No.  Validaton(First 3 letters of room must 'RM_' and length must not greater than 8 characters))
Bhavya LakhotiaBhavya Lakhotia
1) Room No.  Validaton(First 3 letters of room must 'RM_' and length must not greater than 8 characters))