Thanks for sharing, your tip saved my day! ✅
Integer field has a maximum limit of 10 digits?
Collapse
X
-
shalmaxb Ok, I used this formula in the varchar field's condition. But, its showing me invalid if I try to add numbers. Did I wrote something wrote?
PS. Its not required to have exactly 12 digits if its a varchar field, that was the issue with int field.
Leave a comment:
-
As already recommended in thread #2, change the field to BIGINT or VARCHAR. To limit the digits to 12 and only numbers, I guess regex would help. Here the AI solution (did not test it):
To create a regular expression that limits a number to exactly 12 digits and allows only numeric characters, you can use the following pattern:
^[0-9]{12}$
Here’s what each part of the regex means:- ^: The match must start at the beginning of the string.
- [0-9]: Any character between ‘0’ and ‘9’.
- {12}: Exactly 12 occurrences of the preceding character class.
- $: The match must end at the end of the string.
This pattern ensures that the input consists of exactly 12 numeric digits. If you need to allow leading zeros, you can modify it accordingly. ?
For example, the regex would match:- 123456789012
- 000000000001
And it would not match:- 1234567890123 (13 digits)
- abc123456789 (contains non-numeric characters)
- 12345678a901 (contains non-numeric characters)
Feel free to adjust the regex based on your specific requirements12. ?
Leave a comment:
-
I will update soon, is there a way until then? There are two options:
- Use an integer field but it should be able to store 12 digits, currently it stores upto 10 digits. Is there a way to fix that?
- Use a varchar field. Can I put some condition to make this field invalid? (It should show invalid if contains alphabets or special characters)Leave a comment:
-
I recommend updating your instance. You will have to update one day, when espoCRM is already in ver 9 or even 10. And THAT will be difficult. From my experience, it is always preferable to update.Leave a comment:
-
API before save formula only works from version 7.5 and greater -
-
Possible reasons why it doesn't work for you:
- Forum added an extra character at the end of the formula, which you then copied. I already edited it.
- You didn't replace my Varchar field with your own.
- You are confused Administration > Entity Manager > Your_entity_name > Formula > Before Save Custom Script and Administration > Entity Manager > Your_entity_name > Formula > API Before Save Script. For the last option, the formula should be used exactly in API Before Save Script.
Leave a comment:
-
victor Thanks for sharing this formula, but its not working. I have tried the exact formula, but even the alphabets are getting saved now.Leave a comment:
-
shalmaxb gave a very good idea.victor Thank you, this formula works. But, if a value other than 0-9 is put in cForumVarch, I would like it to through an error - Invalid. Can we modify this formula?
1. Delete the formula suggested above https://forum.espocrm.com/forum/gene...942#post106942 from Administration > Entity Manager > Your_entity_name > Formula > Before Save Custom Script.
2. Add the formula in Administration > Entity Manager > Your_entity_name > Formula > API Before Save Script.
PHP Code:$cForumVarch = string\match(cForumVarch, '/^[0-9]*$/');
if (cForumVarch != $cForumVarch) {
recordService\throwBadRequest('field "Forum varch" accepts ONLY 0-9 digits');
}
Last edited by victor; 06-06-2024, 06:53 AM.Leave a comment:
-
-
victor Thank you, this formula works. But, if a value other than 0-9 is put in cForumVarch, I would like it to through an error - Invalid. Can we modify this formula?
Leave a comment:

Leave a comment: