Field validation

I am new to using Suitecrm and I would like to know how to validate a field so that it only receives numerical data without any punctuation.
I created a NIT field in the accounts module, the field is text type but I need it to only receive numbers, I tried to create an integer type field but when saving it generates commas (,) automatically.
I hope you can help me.

Hey there,

Have you found a solution for this, by chance?

I’ve spent some time and managed to scrape something together that seems to force a field to only accept numerical inputs, with a mix of jQuery/Javascript

I’m not sure how clean it is, so if anyone else has any better suggestions, please let us know!


In the file located at: custom/modules/Accounts/metadata/editviewdefs.php

add a reference to a new custom Javascript file, ie:

(I have added the line ‘file’ => ‘custom/modules/Accounts/custAccount.js’)

If this file does not exist, feel free to copy it from
and paste it in the /custom/ location

Create this new javascript file in the same Module folder, ie:

and add the following to the file:

jQuery.fn.ForceNumericOnly =
    return this.each(function()
            var key = e.charCode || e.keyCode || 0;
            // allow backspace, tab, delete, enter, arrows, numbers and keypad numbers ONLY
            // home, end, period, and numpad decimal
            return (
                key == 8 || 
                key == 9 ||
                key == 13 ||
                key == 46 ||
                key == 110 ||
                key == 190 ||
                (key >= 35 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));

Then, create a new extension to the Accounts Edit View at:


and add the following to the file:

class AccountsViewEdit extends ViewEdit
    function display() {
        //Attach the forceNumeric function onto the specified field
        $jsscript = <<<EOQ

            echo $jsscript;     //echo the script

In the above contents, “testjava_c” is the name of my custom field
Please feel free to change this to the name of your custom NIT field

Then, in the CRM run a “Quick Repair & Rebuild” and “Rebuild JS Grouping Files”
Then, clear browser cache

Then, the input on your field should be restricted to only numbers

Does the above work for yourself?

1 Like