Solved

VBScript Regex

Posted on 2014-04-13
3
501 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

713 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