﻿{"id":3551,"date":"2013-08-02T19:32:54","date_gmt":"2013-08-02T10:32:54","guid":{"rendered":"http:\/\/fujiitoshiki.com\/improvesociety\/?p=3551"},"modified":"2017-04-27T15:21:53","modified_gmt":"2017-04-27T06:21:53","slug":"how-to-apply-constraints-to-password-with-regular-expression-which-requires-single-byte-alphanumeric-characters-and-symbols","status":"publish","type":"post","link":"https:\/\/www.fujiitoshiki.com\/improvesociety\/?p=3551","title":{"rendered":"How to validate password with regular expression which requires single-byte alphanumeric characters and symbols?"},"content":{"rendered":"<div class=\"theContentWrap-ccc\"><p>It&#8217;s needed to enter password which requires a character, a number and a symbol at least, respectively. I&#8217;d like to describe how to validate password with VBScript&reg;. It&#8217;s assumed that the length of password is 8 or greater. <\/p>\n<p><a href=\"\/\/fujiitoshiki.com\/improvesociety\/wp-content\/uploads\/EnterPassword.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/fujiitoshiki.com\/improvesociety\/wp-content\/uploads\/EnterPassword-300x106.png\" alt=\"EnterPassword\" width=\"300\" height=\"106\" class=\"alignnone size-medium wp-image-3585\" srcset=\"https:\/\/www.fujiitoshiki.com\/improvesociety\/wp-content\/uploads\/EnterPassword-300x106.png 300w, https:\/\/www.fujiitoshiki.com\/improvesociety\/wp-content\/uploads\/EnterPassword.png 330w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/a><\/p>\n<p>In 23 line, the constraint is shown. In 22 line with comment, it&#8217;s shown that constrains password to require both a single-byte character and number at least and 8 or greater character length. <\/p>\n<pre class=\"toolbar-overlay:true lang:vb decode:true\">Option Explicit\r\n\r\nPrivate Sub CommandButton1_Click()\r\n    With TextBox1\r\n        If Not CheckPassword(.Text) Then\r\n            .SetFocus\r\n            .SelStart = 0\r\n            .SelLength = Len(.Text)\r\n            Exit Sub\r\n        Else\r\n            \r\n        End If\r\n    End With\r\n    Unload Me\r\nEnd Sub\r\n\r\nFunction CheckPassword(InputString As String) As Boolean\r\n    Dim myReg   As Object\r\n    CheckPassword = False\r\n    Set myReg = CreateObject(\"VBScript.RegExp\")\r\n    With myReg\r\n       '.Pattern = \"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,})$\"\r\n        .Pattern = \"(?!^[0-9]*$)(?!^[a-zA-Z]*$)(?!^[!-\/:-@[-`{-~]*$)(?!^[a-zA-Z0-9]*$)(?!^[!-@[-`{-~]*$)(?!^[!-\/:-~]*$)^([!-~]{8,})$\"\r\n        .IgnoreCase = False\r\n        .Global = True\r\n    End With\r\n    If myReg.Test(InputString) Then\r\n        CheckPassword = True\r\n    End If\r\n    Set myReg = Nothing\r\nEnd Function\r\n\r\nPrivate Sub UserForm_Initialize()\r\n    With TextBox1\r\n        .IMEMode = fmIMEModeDisable\r\n        .PasswordChar = \"*\"\r\n    End With\r\nEnd Sub\r\n<\/pre>\n<p>You might need description here. The pattern (?!<em>pattern<\/em>) means such negative lookahead as EXCEPT operator effects in SQL. To seek area three circles overlap, it&#8217;s needed to remove areas around. After filtering out not required patterns with negative lookahead, it validates length of the password. The number of required pattern, which verifies n types of letter, is 2<sup>n<\/sup> &#8211; 2. <\/p>\n<table border=\"0\" align=\"left\">\n<tbody>\n<tr style=\"background-color: #a9a9a9;\">\n<td><span style=\"color: #ffffff; font-family: georgia, palatino;\">Not Needed<\/span><\/td>\n<td><span style=\"color: #ffffff; font-family: georgia, palatino;\">Negative Lookahead Pattern<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-family: georgia, palatino;\">Number<\/span><\/td>\n<td><span style=\"font-family: georgia, palatino;\">(?!^[0-9]*$)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-family: georgia, palatino;\">Character<\/span><\/td>\n<td><span style=\"font-family: georgia, palatino;\">(?!^[a-zA-Z]*$)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-family: georgia, palatino;\">Symbol<\/span><\/td>\n<td><span style=\"font-family: georgia, palatino;\">(?!^[!-\/:-@[-&#096;{-~]*$)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-family: georgia, palatino;\">Character and number<\/span><\/td>\n<td><span style=\"font-family: georgia, palatino;\">(?!^[a-zA-Z0-9]*$)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-family: georgia, palatino;\">Number and symbol<\/span><\/td>\n<td><span style=\"font-family: georgia, palatino;\">(?!^[!-@[-`{-~]*$)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-family: georgia, palatino;\">Character and symbol<\/span><\/td>\n<td><span style=\"font-family: georgia, palatino;\">(?!^[!-\/:-~]*$)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><a href=\"\/\/fujiitoshiki.com\/improvesociety\/wp-content\/uploads\/PasswordValidation.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/fujiitoshiki.com\/improvesociety\/wp-content\/uploads\/PasswordValidation.png\" alt=\"PasswordValidation\" width=\"208\" height=\"204\" class=\"alignnone size-full wp-image-3536\" \/><\/a><\/p>\n<p>References:<br \/>\n<a href=\"\/\/msdn.microsoft.com\/en-us\/library\/az24scfc.aspx\" title=\"Regular Expression Language - Quick Reference\" target=\"_blank\">Regular Expression Language &#8211; Quick Reference<\/a><br \/>\n<a href=\"\/\/msdn.microsoft.com\/en-us\/library\/ms998267.aspx\" title=\"How To: Use Regular Expressions to Constrain Input in ASP.NET\" target=\"_blank\">How To: Use Regular Expressions to Constrain Input in ASP.NET<\/a><br \/>\n<a href=\"\/\/fujiitoshiki.com\/improvesociety\/?p=3539\" target=\"_blank\">ASCII character code list (0-127)<\/a><br \/>\n<a href=\"\/\/fujiitoshiki.com\/improvesociety\/?p=3134\" target=\"_blank\">Userform of Excel VBA as user interface<\/a><\/p>\n<p><iframe style=\"width:120px;height:240px;\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" frameborder=\"0\" src=\"\/\/ws-na.amazon-adsystem.com\/widgets\/q?ServiceVersion=20070822&#038;OneJS=1&#038;Operation=GetAdHtml&#038;MarketPlace=US&#038;source=ss&#038;ref=ss_til&#038;ad_type=product_link&#038;tracking_id=improsocie-20&#038;marketplace=amazon&#038;region=US&#038;placement=0596528124&#038;asins=0596528124&#038;linkId=JK3BQGG7EG6X7X3N&#038;show_border=true&#038;link_opens_in_new_window=true\"><br \/>\n<\/iframe><\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>It&#8217;s needed to enter password which requires a character, a number and a symbol at least, respectively.  &hellip; <a href=\"https:\/\/www.fujiitoshiki.com\/improvesociety\/?p=3551\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;How to validate password with regular expression which requires single-byte alphanumeric characters and symbols?&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":3536,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[6],"tags":[342,358,350,352,603,353,354,357,348,351,349,359,361,360,356,153,336],"class_list":["post-3551","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-excel","tag-342","tag-character","tag-character-class","tag-escape","tag-excel","tag-meta-character","tag-negative-lookahead","tag-number","tag-password","tag-pattern","tag-regular-expression","tag-symbol","tag-textbox","tag-userform","tag-validation","tag-vba","tag-vbscript"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/posts\/3551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3551"}],"version-history":[{"count":27,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/posts\/3551\/revisions"}],"predecessor-version":[{"id":7734,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/posts\/3551\/revisions\/7734"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=\/wp\/v2\/media\/3536"}],"wp:attachment":[{"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fujiitoshiki.com\/improvesociety\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}