Validate Textbox Input to be only Alphabets and number

Hi

I am having a batch code text box, when user entered value in it need to validate. Value entered should be in the following format ##CCC#CC (# is number and C is alphabet).

Any way i can do this, or code for validating input to be in the above format.

Thnaks

Priya

match() function or .NET class Regex may be the way to go, but the implementation depends a lot on your definition of “alphabet”. For example, maybe a-z characters is all you need, or maybe it would be completely useless because you’re working with, say, Chinese. Can you tell us more about your requirements, please?

My requirement is warehouse workers use RF device, they manually enter batch code into RF for each finished good and click ok. when they click ok we need to validate that text box for the format. it should be like 03DEC8MR, just numbers and alphabets. Now text box is accepting anything when we send an edi to other system its causing issues, so we need validation on this. It should just be ##CCC#CC where C- only alphabets. It will just be in English no other languages.

Where do i need to write this validation, please explain?

Thanks

I would validate it with the Regex class:

System.Text.RegularExpressions.Regex::IsMatch(textToCheck, @'^\d{2}[A-Z]{3}\d[A-Z]{2}$');

Where exactly you should do it depends on the place you’re working with and your requirements.

Thanks.

Hi Martin,

Where and how can i assign regular expression pattern to EDT string field of a table as i want to pass this as parameter not directly hard code this pattern?

Thanks

If i want to hard code i can do it like below

Like

Str RegEx = @’^\d{2}[a-zA-Z]{3}\d[a-zA-Z]{2}$’;

In class I can validate like below

if(! System.Text.RegularExpressions.Regex::IsMatch(BatchId, RegExp)

{

Error

}

But i cant hard code pattern here in class

Please help.

Thanks

If you mean you want to reuse in code, you can create a constant (if it’s actually constant), hide it in a method or something.
If you want allow users top define the pattern, you can put it into a field in a parameter table. But I’m not sure how many of them are familiar with regular expressions.

okay, one more question.

Do we need any reference model to use System.Text.RegularExpressions.Regex::IsMatch. Because its giving me error like it does not denote table,class or EDT?

How i refer to the class having Regex::ismatch() method?

Thanks

No, you don’t need any reference, because it’s not an AX class. It’s a .NET class and it’s included in the standard .NET framework.

Note that .NET types are case-sensitive. While the class has IsMatch() method, it doesn’t have ismatch() and your code won’t compile with ismatch().

Okay, Thanks. That helped.