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. Regular Expressions
  4. Regular expression to check special character

Regular expression to check special character

Scheduled Pinned Locked Moved Regular Expressions
regexhelpquestion
2 Posts 2 Posters 6 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.
  • S Offline
    S Offline
    sri_3464 0
    wrote on last edited by
    #1

    I need to check whether password has at least 6 characters with at least 1 letter and one special character. I am checking the condition !Regex.IsMatch(strPassword,"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,24})$"). But it doesnot allow special character. I need to change the expression to check if there is at least one special character. Please help me out.

    M 1 Reply Last reply
    0
    • S sri_3464 0

      I need to check whether password has at least 6 characters with at least 1 letter and one special character. I am checking the condition !Regex.IsMatch(strPassword,"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,24})$"). But it doesnot allow special character. I need to change the expression to check if there is at least one special character. Please help me out.

      M Offline
      M Offline
      Mizard X
      wrote on last edited by
      #2

      ^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[^a-zA-Z0-9]).{6,}$

      1. ^ checks for the start of the input string.
      2. (?=.*[a-zA-Z]) checks that there are at least one letter.
      3. (?=.*[0-9]) checks that there are at least one digit.
      4. (?=.*[^a-zA-Z0-9]) checks that there are at least one special character (not a letter nor digit).
      5. .{6,} checks that there are at least 6 characters.
      6. $ checks for the end if the input string.

      See also

      • XKCD: Password Strength

      -- MizardX (so)

      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