Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Validate alpha numeric.

SD29
Tera Expert

Hi All,

I have a requirement where I have to validate a single line text field to have alpha-numeric characters. I have written this onChange script as below, but I think it's not working as expected.

please help me.

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue == '') {

          return;

    }

  g_form.hideFieldMsg('SAP Customer Number');

  var patt = "^[a-zA-Z0-9]*$";

  if (!patt.test(newValue))

  g_form.showFieldMsg('SAP Customer Number','Invalid input','error');

  var patt2 = "^[Nn]/[Aa]$";

  if (!patt.test(newValue))

  g_form.showFieldMsg('SAP Customer Number','Invalid input','error');

   

}

Thanks in Advance,

SD

1 ACCEPTED SOLUTION

I understood the requirement. This time though, I'll repeat the earlier statement and show you the code.




you dont need a regeexp for that. Use .length property of newValue to check.



translates to



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



if(!patt.test(newValue) || newValue.length != "10"){


        // error out.


}


View solution in original post

5 REPLIES 5

I understood the requirement. This time though, I'll repeat the earlier statement and show you the code.




you dont need a regeexp for that. Use .length property of newValue to check.



translates to



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



if(!patt.test(newValue) || newValue.length != "10"){


        // error out.


}