Regular Expressions

S

Steve

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 at any time.

I haven't used Regular Expressions before so I'm not sure if they can be
used with this. If they can, then could some-one please provide a code
snippet of what the expression should be for the rule in the example above,
and any good links to regular expressions articles are most welcome!!!

Kind regards,
Steve.
 
S

Steve

Hiya

Thanks for that. How can I get the regular expression I want for my example
that I posted? It looks like it's a testing facility to test an expression,
but I need to find out an expression based on my rules.

Let me know if I'm looking at it wrong!

Kind regards,
Steve
 
N

Nick Malik

Hi Steve,

Honestly, you will take more time to code and debug the regex than it would
take you to write the hard-coded checking routine... twice. In addition,
regex is much better suited to looking for patterns of combinations,
extracting parts of complex strings, etc. For a string that is nearly
always less than 20 characters long, regex is an expensive overkill.

I fall back on ideas common in agile computing: Use the least complicated
method, every time. If no one has asked for the ability to store a pattern
in a config file, then you are "goldplating." It's a bad habit.

My opinion: Hard code the rule. Document where it is. Put an NUnit test
(or three) on it.

--- Nick
 
S

Steve

Hi Nick

Thanks for the advice. I guess I'll just hard-code it. The least complicated
method is usually the one that I'd use, however, when the method is based on
rules that may change, to have an application that can handle rule changes
after it's been written and deployed is a good selling point. I was hoping
to learn more about RegEx as well, maybe another day ....

Kind Regards,
Steve.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top