Solved

VBScript Regex

Posted on 2014-04-13
3
504 Views
1 Endorsement
Last Modified: 2014-05-06
Hi,

I am looking to get a regex pattern for VBScript that can validate the following

1. A Minimum string must be at least 1 character
2. Maximum length of 15 characters.
3. Must have at lease one alphabetic character (A-Z)
4. Can also accept any of the following characters (0-9) and a hypen (-).

Thanks,

Ward.
1
Comment
Question by:whorsfall
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39997169
(?=.*[A-Z])[A-Z0-9-]{1,15}

If you want to accept small letters too, use

(?=.*[A-Za-z])[A-Za-z0-9-]{1,15}

HTH,
Dan
0
 
LVL 27

Expert Comment

by:skullnobrains
ID: 39997456
i'd assume password validation that requires at least one capital letter

(?=.*[A-Z])[A-Za-z0-9-]{1,15}
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 39997831
Unless it's already implied by VBScript's implementation of regexes, you'll also want to put a start and end of string placeholder on your pattern:
^(?=.*[A-Z])[A-Za-z0-9-]{1,15}$

Open in new window

If you don't, the following illegal (and potentially risky) value would be valid, as the A at the end would match:
!@#$%^&*()</input>';drop table students; '%^$^&&*^*&(A

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question