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!
Anyways;
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
modules/Accounts/metadata/editviewdefs.php
and paste it in the /custom/ location
Create this new javascript file in the same Module folder, ie:
custom/modules/Accounts/custAccount.js
and add the following to the file:
jQuery.fn.ForceNumericOnly =
function()
{
return this.each(function()
{
$(this).keydown(function(e)
{
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:
custom/modules/Accounts/views/view.edit.php
and add the following to the file:
<?php
class AccountsViewEdit extends ViewEdit
{
function display() {
//Attach the forceNumeric function onto the specified field
$jsscript = <<<EOQ
<script>
$('#testjava_c').ForceNumericOnly();
</script>
EOQ;
parent::display();
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?