Announcing the Global SNUG Board of Directors. Learn more here

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Heleno Martins2
Giga Contributor

Script created to validate the number entered, from 1 (one character) to 100000000000 (twelve characters)

 

Below is a CLIENT SCRIPT using REGEX to validate a STRING type field, allowing only INTEGER NUMERIC to be inserted, without "." (dot) and "," as for LETTERS,

it will not be necessary, as the INTEGER field type itself already changes the value entered in LETTERS for "0":

  • For UP to THREE numerals use: /(^[0-9]*$)/
  • For UP to SIXnumerals use: /(^[0-9]+,[0-9]*$)/
  • For UP to NINE numerals use: /(^[0-9]+,[0-9]+,[0-9]*$)/
  • For UP to TWELVE numerals use:/(^[0-9]+,[0-9]+,[0-9]+,[0-9]*$)/
  • REGEX containing the FOUR previous validations: /(^[0-9]*$)|(^[0-9]+,[0-9]*$)|(^[0-9]+,[0-9]+,[0-9]*$)|(^[0-9]+,[0-9]+,[0-9]+,[0-9]*$)/

Follow the steps below:

  • Create a field called "Test_Integer" on your table:
  • Table: (your table);
  • Type: Integer;

find_real_file.png

 

 

  • Create an OnChangeClient Script called "Validate Integer Numeric":
  • Name: Validate Interger Numeric;
  • Table: Select Your Table;
  • UI Type: All or Desktop;
  • Type: OnChange;
  • Field Name: Test_Integer.

find_real_file.png

 Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}

//Variable created containing the regex that validates if the value entered is WHOLE NUMBER ONLY

var regExTest /(^[0-9]*$)|(^[0-9]+,[0-9]*$)|(^[0-9]+,[0-9]+,[0-9]*$)|(^[0-9]+,[0-9]+,[0-9]+,[0-9]*$)/;

//Validation condition using the REGEX variable.

if ((newValue == 0) || (!regExTest.test(newValue))) {
alert(''Please enter only Numbers. For Example: (1 or 1000 or 1000000) - Without "." and either ","!'); //Enter THERE the MESSAGE to ALERT that you would like the USER to receive when typing wrong.
g_form.setValue('u_test_integer', ''); //Insert your field to be cleared after the ALERT confirmation.
}

}

find_real_file.png

 

 

Obs.:

If your field is not inserted in the form automatically, insert it manually following the steps below:

 

1 - Expand a record of your table:

find_real_file.png

 

 

2 - Click on the Burguer located in the upper left corner:
find_real_file.png

 

 

3 - Then click on "CONFIGURE" and "FORM LAYOUT":

find_real_file.png

 

 

4 - Choose the POSITION you want to insert it and Transfer the FIELD "TEST INTEGER" in the LEFT list to the RIGHT list by clicking on the ">" ARROW located in the center of the screen:

 find_real_file.png

 

 

Tests:

Create a new record in your table and insert the characters in the field to be validated: find_real_file.png

 

 

Test 1: Insert only TEXT and press TAB: find_real_file.png

 

 

Test 2: Click in OK and Insert two or more numbers separated by dot (.) And press TAB: find_real_file.png

 

Test 3: Click in OK and Insert FOUR or MORE numbers and hit TAB (Allow value inserted with four characters):find_real_file.png

Comments
User378568
Giga Explorer

Thanks for sharing this!!!

Version history
Last update:
‎06-18-2020 08:04 PM
Updated by: