Skip to main content

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

@aishwarya 

Hi, Is this for FSM mobile?

 

Thanks,

Morris


@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 @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 @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).  


@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. 


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 @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

 


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 = isUppercaseAndNumberss0];
if(row != null)
{
var trueFalse = roww"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 @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 = isUppercaseAndNumbersr0];
if(row != null)
{
var trueFalse = rowo"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