how to set alphanumeric values on variable field

Nagendra Rao Si
Tera Contributor

Hi,

 

How to set aplhanumeric only in variable using on change client script,Please help on this below script is not executing as expected

 

var patt = new RegExp("^[a-zA-Z0-9]*$");

 

if(!patt.test(newValue)){


// error out.
g_form.showFieldMsg('cost_center_sw', 'Invalid input', 'error');


}

 

Thanks

5 REPLIES 5

OlaN
Giga Sage
Giga Sage

Hi,

Try entering the pattern this way instead:

var pattern = /^[a-zA-Z0-9]*$/;

Hi Olan,

 

That is not execute As expected

 

Thanks

Is this to validate input for a variable in a Catalog item?

If so, I would recommend you create a regular expression and use it to validate the value.

Navigate to: Service Catalog > Catalog variables > Variable Validation Regex

Create a new record, input the expression you have, and then use that new record to validate the input on your Catalog variable.

SanjivMeher
Kilo Patron
Kilo Patron

I tested and it works with both new RegExp("^[a-zA-Z0-9]*$"); and /^[a-zA-Z0-9]*$/.

The only thing is it also accepts just characters for ex 'abcd'. Is that were it fails for you.

var abc = 'abcd123';
var patt = /^[a-zA-Z0-9]*$/;
gs.info(patt.test(abc));

Please mark this response as correct or helpful if it assisted you with your question.