Solved

VBScript Regex

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

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 26

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

777 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