-2

I am looking for a code that will validate custom values into the textbox for a window form such that the input entered follows a certain pattern as shown-

|"DB1.DBX1.0"|"DB1000.DBB1000.0"|"DB18.DBD4.0"|"DB99.DBW999.0"| 

such that DB[1-1000].DB[X,B,D,W][1-1000.0-10] and if the values match the required pattern the valued would be accepted or else it will show an error.

I have also attached textbox image for the reference.

The textbox looks like such:

Biffen
  • 5,354
  • 5
  • 27
  • 32
Pikachu
  • 19
  • 6
  • 1
    Possible duplicate of [Learning Regular Expressions](http://stackoverflow.com/questions/4736/learning-regular-expressions) – Biffen Mar 08 '17 at 10:50

2 Answers2

0

You can try that :

DB(1000|0[1-9]|[1-9]\d{0,2})\.DB[XBDW](1000|0[1-9]|[1-9]\d{0,2})\.(0|10|[1-9])

Explanation:

  1. DB matches DB at the start
  2. (1000|0[1-9]|[1-9]\d{0,2}) matches 1000 or 01-09 or [1-9] followed by 0 or 1 or two digits
  3. \. matches dot
  4. DB matches DB
  5. [XBDW] matches any X or B or D or W
  6. (1000|0[1-9]|[1-9]\d{0,2}) matches 1000 or 01-09 or [1-9] followed by or or 1 or two digits
  7. \. matches dot
  8. (0|10|[1-9]) matches zero or ten or anything between 1 and 9

Demo

Update to your comment:

DB(\d{1,4}|[1-5]\d{5}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])\.DB[XBDW](1000|0[1-9]|[1-9]\d{0,2})\.(0|10|[1-9])

Demo 2

Rizwan M.Tuman
  • 9,424
  • 2
  • 24
  • 40
  • This is matching `DB00.DBX00` – Toto Mar 08 '17 at 11:19
  • I tried but it wasn't matching , the thing is your pattern wasn't complete... i have understood your context though your sample wasn't a full text... thanks – Rizwan M.Tuman Mar 08 '17 at 11:43
  • Only OP can say. Just another remark, the last part can be reduce to `10|\d`, and I don't know if `DB01` is allowed or `DB001`, I'd say `DB(1000|[1-9]\d{0,2})`. I'll give you +1 if OP accepts your answer. – Toto Mar 08 '17 at 12:33
  • @RizwanM.Tuman how do i match a number that is upto 65535. Incase of value uptil 1000 i have understood that 1001 wouldn't be accepted in your expression which is :(1000|0[1-9]|[1-9]\d{0,2}) ***Kindly give me an expression for DB[X][1-65535]*** – Pikachu Mar 10 '17 at 10:19
  • Although this was not your original question, yet I have uodated my answer... Plz accept the ans if that served your purpose – Rizwan M.Tuman Mar 10 '17 at 10:40
0

Try this one please. It works in java.

DB((\d{1,3})|(1000))\.DB(X|B|D|W)((\d{1,3})|(1000))\.((\d{1})|(10))
Arman
  • 71
  • 3