Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. HELP NEEDED WITH REGEX

HELP NEEDED WITH REGEX

Scheduled Pinned Locked Moved Visual Basic
regexhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    roychoudhury_sudip
    wrote on last edited by
    #1

    I need to validate a password field with RegularExpression Validator. The validation logic is bit complex for me. Can anyone help me out with this Password must be a minimum of 8 characters and contain a combination of 3 of the following characters: - numbers - upper case letters - lower case letters - special character (*%$) I need this urgently. PLEASE SOMEONE PLS HELP. THANKS in advance

    H 1 Reply Last reply
    0
    • R roychoudhury_sudip

      I need to validate a password field with RegularExpression Validator. The validation logic is bit complex for me. Can anyone help me out with this Password must be a minimum of 8 characters and contain a combination of 3 of the following characters: - numbers - upper case letters - lower case letters - special character (*%$) I need this urgently. PLEASE SOMEONE PLS HELP. THANKS in advance

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      A regular expression to do this (mostly because of the 3 out of 4 clause, would be incredibly long and would require intensive CPU time and quite a bit of memory. I would recommend that you instead create a custom validator that enumerates the characters and keeps a count, something like this:

      ' Assume password is in a string variable called "password"
      If password.Length < 8 Then Return False
      Dim i As Integer = 0
      Dim b1 As Boolean
      Dim b2 As Boolean
      Dim b3 As Boolean
      Dim b4 As Boolean
      For Each c As Char In password
      If Char.IsLetter(c) Then
      If Char.IsLower(c) And Not b1 Then
      b1 = True
      i++
      Else If Not b2
      b2 = True
      i++
      End If
      Else If Char.IsNumber(c) And Not b3 Then
      b3 = True
      i++
      Else If (c = "*"c Or c = "%"c Or c = "$"c) And Not b4 Then
      b4 = True
      i++
      End If
      Next

      If i >= 3 Then Return True
      Else Return False

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups