mardi 7 février 2017

Using a regular expression to validate an zip code

A string must contain the following

  1. 123, => Three digits with Comma
  2. 123 => Three digits with Nothing
  3. ,123 => Comma with Three digits
  4. 1234567, => Seven digits with Comma
  5. 1234567 => Seven digits with Nothing
  6. ,1234567 => Comma with Seven digits

Maybe you don't understand what I want, so let me give you an example

=================================

123-------------------------right
1234------------------------wrong
123,1234----------------wrong
,123-------------------------right
,123,------------------------right
123,123--------------------right
123,123,-------------------right
123,1234567-------------right

The three digits can be replaced by a number of seven digits




Aucun commentaire:

Enregistrer un commentaire