Single-byte numbers, single-byte spaces, and symbol validation

Kentaro Numata
Tera Guru

Hello.

I'm creating a validator that checks the entered value with a business rule.

Ultimately, I want to allow half-width alphanumeric characters, half-width spaces, and symbols.

Is it possible to create a regular expression that allows all double-byte characters?

 

Below is the script I am working on.
Only single-byte numbers are allowed.
I want to add a half-width space and a symbol.

Could you tell me how to fix it?

 

Thanks,

Kentaro.

---

(function executeRule(current, previous /*null when async*/) {
     var result = true;
     var pattern = new RegExp(/^[a-zA-Z0-9]+$/);
     if (!pattern.test(current.u_cpu)) {
          gs.addErrorMessage(gs.getMessage("Enter the CPU in single-byte alphanumeric characters."));
          current.u_cpu="";
          result = false;
     }

     if(result == false){
          current.setAbortAction(true);
     }

})(current, previous);

1 ACCEPTED SOLUTION

Kentaro Numata
Tera Guru

I fixed it with the following regular expression. I am checking if it is a 2-byte character.

I am checking if it is a 2-byte character.

 

[ -~。-゚]

View solution in original post

2 REPLIES 2

Tony Chatfield1
Kilo Patron

Hi, there are a number of online regex tools which should help you with your requirement.
regex101: build, test, and debug regex is one example

Based on the details provided I suspect you would need something like
[a-zA-Z0-9]+[ ][-]

Kentaro Numata
Tera Guru

I fixed it with the following regular expression. I am checking if it is a 2-byte character.

I am checking if it is a 2-byte character.

 

[ -~。-゚]