Skip to main content
Solved

How to use Regular expression in client

  • 26 July 2024
  • 9 replies
  • 76 views

Hi,

I want to write query in client script for validation.

requirement- A particular field (in mobile application) should be in capital letter and numbers. So, i want to use regular expression.

expression i am using-  ^ A-Z0-9] $ 

Problem - How to use this expression and how to write the query for this.

can anyone help me on this 

 

Thanks in advance

9 replies

Userlevel 3
Badge +7

@aishwarya 

Hi, Is this for FSM mobile?

 

Thanks,

Morris

Userlevel 2
Badge +4

@aishwarya 

Unfortunately, as far as I’m aware, we don’t have access to a Regex function within the mobile client scripts.  I have worked around this in the past using string manipulation. For example, if you can create a default mask that the field should be: the Field must contain two capital letters (A-Z) followed by six numbers (0-9) you could create a known default string &&######. After you get the user input, you can use a series of stringReplace functions (yes it would be a lot of coding) to convert letters to the & character and numbers to the # character.  In the end the user input would either be correctly converted to match the default string or would have out of place characters in the string.  

TZ123456 → &&###### → Match valid

Tz654321 → &z###### → No Match invalid

Y7F78123 → &#&##### → No Match invalid

I know this would be a lot of coding for a single field validation, but it technically would do the job. You really just need to know if the string being entered can be masked to a single default value or maybe even a few default values. 

Userlevel 7
Badge +26

Hi @aishwarya 

How about using the ‘UPPER’ mask type in custom metadata? and skip the validation.

If not, then use the regex in custom metadata.

Cheers!

Badge +4

Hi @aishwarya 

How about using the ‘UPPER’ mask type in custom metadata? and skip the validation.

If not, then use the regex in custom metadata.

Cheers!

Hi @Shneor Cheshin 

all the data i am fetching from global code ad using it in the client script. In mobile application using the script we are validating the column. another problem is not able to modify base table (ESCALATION).  

Badge +4

@aishwarya

Unfortunately, as far as I’m aware, we don’t have access to a Regex function within the mobile client scripts.  I have worked around this in the past using string manipulation. For example, if you can create a default mask that the field should be: the Field must contain two capital letters (A-Z) followed by six numbers (0-9) you could create a known default string &&######. After you get the user input, you can use a series of stringReplace functions (yes it would be a lot of coding) to convert letters to the & character and numbers to the # character.  In the end the user input would either be correctly converted to match the default string or would have out of place characters in the string.  

TZ123456 → &&###### → Match valid

Tz654321 → &z###### → No Match invalid

Y7F78123 → &#&##### → No Match invalid

I know this would be a lot of coding for a single field validation, but it technically would do the job. You really just need to know if the string being entered can be masked to a single default value or maybe even a few default values. 

Hi @Kerry Sitler 

Yes you are right. regular expression is not working in the script. 

Userlevel 7
Badge +26

Hi @aishwarya 

How about using the ‘UPPER’ mask type in custom metadata? and skip the validation.

If not, then use the regex in custom metadata.

Cheers!

Hi @Shneor Cheshin 

all the data i am fetching from global code ad using it in the client script. In mobile application using the script we are validating the column. another problem is not able to modify base table (ESCALATION).  

 

Hi @aishwarya 

Sorry, but I am not following your answer.

Can you please rephrase?

Cheers!

Badge +4

Hi @aishwarya 

How about using the ‘UPPER’ mask type in custom metadata? and skip the validation.

If not, then use the regex in custom metadata.

Cheers!

Hi @Shneor Cheshin 

all the data i am fetching from global code ad using it in the client script. In mobile application using the script we are validating the column. another problem is not able to modify base table (ESCALATION).  

 

Hi @aishwarya 

Sorry, but I am not following your answer.

Can you please rephrase?

Cheers!

Hi @Shneor Cheshin 

In my requirement , Fetching all the data from global code table and using those global code in the client script. In the mobile application , using the script we are validating our required fields. I tried to add regular expression in the table using alter script .Due to baseline table i am not able to alter table. so can you please suggest another approach

 

Userlevel 7
Badge +26

Hi @aishwarya 

You can try using SQLite for that.

For example (Did not test this in Mobile client)

var myField = getControlValue('myTable', 'myControl');
var isUppercaseAndNumbers = getDBValue(stringFormat("SELECT CASE WHEN '{0}' REGEXP '^[A-Z0-9]+$' THEN 'TRUE' ELSE 'FALSE' END AS is_uppercase_and_numbers;",myField));
if (isUppercaseAndNumbers != null)
{
var row = isUppercaseAndNumbers[0];
if(row != null)
{
var trueFalse = row["is_uppercase_and_numbers"];
}
}
if(trueFalse == 'TRUE')
{
do sonething;
}
else
{
do something else;
}

 

I got the following results in the SQLite DB tool

 

 

Cheers!

Badge +4

Hi @aishwarya 

You can try using SQLite for that.

For example (Did not test this in Mobile client)

var myField = getControlValue('myTable', 'myControl');
var isUppercaseAndNumbers = getDBValue(stringFormat("SELECT CASE WHEN '{0}' REGEXP '^[A-Z0-9]+$' THEN 'TRUE' ELSE 'FALSE' END AS is_uppercase_and_numbers;",myField));
if (isUppercaseAndNumbers != null)
{
var row = isUppercaseAndNumbers[0];
if(row != null)
{
var trueFalse = row["is_uppercase_and_numbers"];
}
}
if(trueFalse == 'TRUE')
{
do sonething;
}
else
{
do something else;
}

 

I got the following results in the SQLite DB tool

 

 

Cheers!

hi @Shneor Cheshin ,

Thank you so much for your replay. Let me try this and let you know. Hope this will work

Reply