0

I'm trying to validate an input field value that has the following validatino rules:

  1. Either a number, OR
  2. A number with a trailing 'A', 'K', or 'W'

some valid values : '1', '12', '1A', '12W' some invalid values : 'A', 'abc', '11A1', '1 A'

Any pointer appreciated. Thx

2
  • 3
    Please post the code you have written so far. People generally do not like to just write your code for you. Commented Jun 19, 2011 at 9:48
  • The problem would appear easier if the description said "a number with an optional trailing letter". Also, what sort of a text box? Webforms? MVC? WPF? Windows Forms? Other? And what is a number? How about negative numbers, or decimals? Commented Jun 19, 2011 at 9:54

1 Answer 1

4
/^\d+[AKW]?$/ 

\d+ means one or more digits. [AKW]? matches one A or K or W, or nothing (? could be interpreted as meaning "optional"). The ^ and $ are anchors that match the start and end of the string respectively.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.