• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic