473,595 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regular Expression in password

I want to ensure a password has a least one lower case letter, one upper
letter and a number. I'm a bit of a newbie but I understand you can use the
pipe system for OR what about AND.I would like something like this.

[a-z]&[A-Z]&[1-9]
Feb 3 '07 #1
4 4725
Hi,
Try following expresion:
var regexp = /^\w*(?=\w*\d)(? =\w*[a-z])(?=\w*[A-Z])\w*$/
If you find this post useful then please do click yes at "Was this post
helpful to you"

Thanks and Regards,
Manish Bafna.
MCP and MCTS.
"Chris" wrote:
I want to ensure a password has a least one lower case letter, one upper
letter and a number. I'm a bit of a newbie but I understand you can use the
pipe system for OR what about AND.I would like something like this.

[a-z]&[A-Z]&[1-9]
Feb 3 '07 #2
Chris wrote:
I want to ensure a password has a least one lower case letter, one upper
letter and a number. I'm a bit of a newbie but I understand you can use the
pipe system for OR what about AND.I would like something like this.

[a-z]&[A-Z]&[1-9]

There is no and operation in regular expressions. It's not useful, as a
character can not be a lower case letter, an upper case letter and a
digit at the same time. Each character is only one of these.

You can express your demands like any of several different patterns:

something-upper-something-lower-something-digit-something
something-upper-something-digit-something-lower-something
something-lower-something-upper-something-digit-something
something-lower-something-digit-something-upper-something
something-digit-something-upper-something-lower-something
something-digit-something-lower-something-upper-something

The first one would be expressed as:

..*[A-Z].*[a-z].*[1-9].*

Express the others similarly, and put them togther with the or operator:

(.*[A-Z].*[a-z].*[1-9].*)|(...)|(...) ...

--
Göran Andersson
_____
http://www.guffa.com
Feb 3 '07 #3
Göran Andersson wrote:
Chris wrote:
>I want to ensure a password has a least one lower case letter, one
upper letter and a number. I'm a bit of a newbie but I understand
you can use the pipe system for OR what about AND.I would like
something like this. [a-z]&[A-Z]&[1-9]


There is no and operation in regular expressions.
There is.
See Manish's post.

See also www.regexlib.com and search for "password"

--

Riki
Feb 3 '07 #4
Riki wrote:
Göran Andersson wrote:
>Chris wrote:
>>I want to ensure a password has a least one lower case letter, one
upper letter and a number. I'm a bit of a newbie but I understand
you can use the pipe system for OR what about AND.I would like
something like this. [a-z]&[A-Z]&[1-9]

There is no and operation in regular expressions.

There is.
See Manish's post.

See also www.regexlib.com and search for "password"
That's not an and operation. It's a zero-width positive lookahead.

--
Göran Andersson
_____
http://www.guffa.com
Feb 4 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
10346
by: Ron Adam | last post by:
Is it possible to match a string to regular expression pattern instead of the other way around? For example, instead of finding a match within a string, I want to find out, (pass or fail), if a string is a partial match to an re. Given an re of 'abcd and a bunch of other stuff' This is what i'm looking for:
4
305
by: Steve | last post by:
Hi all I have to validate a password to determine whether or not it adheres to certain rules. For example, the password must contain at least 1 number, at least 1 uppercase character and at least 1 lowercase character. Are regular expressions the way to perform this validation? I know I can hard-code it in at the moment, but the rules may change in the future and I'd like to store the expression in an external file so it can be altered...
5
2314
by: Henry | last post by:
I have this simple code, string escaped = Regex.Escape( @"`~!@#$%^&*()_=+{}\|;:',<.>/?" + "\"" ); string input = @"a&+" + "\"" + @"@(-d)\e"; Regex re = new Regex( string.Format(@"(+)", escaped), RegexOptions.CultureInvariant ); string s = re.Replace( input, "" ); It doesn't seem to work, regular expression return without filter out any character
9
2183
by: Stirling | last post by:
Hi all, hope someone can help me, I am looking to do a password validation check using client side validation. Minimum requirement is that it must contain at least one number and one letter. (Ideally it would be of 6-20 characters in length but first things first). I have came up with the following regEx
3
2137
by: Ryan Taylor | last post by:
Hello. I am trying to create a regular expression that will let me know if a string has the following criteria. Order does not matter in the string, but when building a regular expression it does, right? I am brand new to regular expressions and having a little (read: a lot of) difficulty in making a regular expression that makes sure the string meets the following rules. The string contains at least one character from two of the...
2
299
by: Peter Rietmann | last post by:
I have the problem to validate a password with a length of at least 6 and maximum 15 and the condition that it contains at least 2 numbers ie. (1aaaa1, aaaa11, 11aaaa). I am using the microsoft Regular Expreession Validation Control. I have tried the following at the web site http://www.regexlib.com/RETester.aspx ^(?=.*?\d.*?\d)({6,15})$
6
1210
by: vvenk | last post by:
Hello: I am trying to learn about regular expressions. How would I use regular expressions to ensure that the password an user enters conforms to the following rules: 1. It has to be between 3-20 characters long. 2. Only a-z, A-Z, 0-9, +-_ are allowed. 3. At least one occurence of a lower case letter, a upper case letter and a
7
2714
by: JJ | last post by:
To validate a password as the user is registering I want to use a regular expressio validator. I got this one from the Microsoft web site for validating a password of at least 7 characters, with at least one number and one non-alphanumeric character: @\"(?=.{7,})(?=(.*\d){1,})(?=(.*\W){1,}) Yet I can't get it to validate that a password like qwertyui123# fits the
18
622
by: Lit | last post by:
Hi, I am looking for a Regular expression for a password for my RegExp ValidationControl Requirements are, At least 8 characters long. At least one digit At least one upper case character
0
1975
by: AAaron123 | last post by:
Been playing with asp:changepassword and have it looking OK except that I can't elininate or change the title at the top that says "Change Your Password". It's a repeat of my pages title. But more importantly, I can't find the regular expression for at least 7 characters and at least 1 special character. Can you help?
0
7955
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7883
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8251
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5418
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3873
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2391
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.