• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Mask - regular expressions

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm having trouble coming up with the correct regular expressions to use in mask. The field I need to validate has the following rules:
1.length should be 10 characters - using minlength and maxlength for this - and it works fine.
2.accepted chars are 0 to 9 and the letter X - the value in my validation.xml is as follows:
<var>
<var-name>mask</var-name>
<var-value>^[0-9X]$</var-value>
</var>
Am I setting up the regular expression incorrectly ? Any pointers will be very helpful.

Thanks,
Mallika.
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The regex you've setup says: The string is valid if it contains 0-9 or X and one character long, you'll need to add that you want it to be 10 characters long.

^[0-9X]{10}$

Given that you are now checking it's length with the regex, you can get rid of the min/max length bits if you want.
 
Mallika R Kumar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ray - I changed th mask value, and it works now.
 
Mallika R Kumar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
The field I need to validate needs to be 10 characters long, and can contain numbers 0 to 9, and the letter X. The mask value I have set up is:
<var-name>mask</var-name>
<var-value>[0-9X]${10}</var-value>

This allows the following value to be entered and saved, which is not acceptable.
345678yyy8
Is my regular expression incorrect ? Any hints will be greatly appreciated.

Thanks,
Mallika.
 
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic