Validating string length with regular expressions

Results 1 to 2 of 2

Thread: Validating string length with regular expressions

  1. #1
    Tony Guest

    Default Validating string length with regular expressions

    Does anyone know a way to validate a string length using regular expressions? I need to validate credit card numbers, and the length of the number is either 13 or 16 digits. As I am using the RegExp object already, I would like to use it for the length as well. <BR><BR>For instance, VISA numbers can be either 13 or 16 digits in length, and must begin with a 4. This pattern ("4d{15}") works just for determining the first digit as 4, and ensuring that the remaining characters, up to 15 of them, are digits. It also ensures that the user inputs at least 16 digits. It doesn&#039;t verify that the string length itself is 16, though. I can put in a 24 character string, and as long as the first digit is 4, and the next 15 characters are digits, it will pass. <BR><BR>I know I can use len(card_num), but I would like to stick with one method of verifying. Any help is greatly appreciated. <BR><BR>I am fairly new to regular expressions, too = P

  2. #2
    Tony Guest

    Default N/M. I found it

    Always happens that way. Search for hours, post the question out of desperation, then find the answer. Bah.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts