Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8687239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:04:17+00:00 2026-06-12T23:04:17+00:00

I am trying to use regular expressions with my C# code, and I can

  • 0

I am trying to use regular expressions with my C# code, and I can find a few examples here on what those regular expressions might look like for my cause, but nowhere can I tell how I am supposed to (syntactically) implement that into my logic and code.

I have tried setting up an external .cs file and then calling the method, but the value returned is unable to be casted or worked with in any way.
The code can be found here:Checking strings for a strong enough password

In any event, I just want to know how I can check (and test against) values in a password to make sure it is up to standards that I specify.

A better way than suggesting to use regular expressions (since information on how to incorporate them into my own specific logistical setup is both very sparse and very confusing)

…is suggesting how it can be done without them.

I know I could use

foreach(char c in myString)

and then test individually, character by character, but I was hoping there was a better way that can either be regex, explained (that is, explained how to call this suggestion into action, not just posting a string of seemingly (but not) random characters and told, hey use that!), or not using regex at all, but somekind of shorthand, perhaps.

Truth is I would use regular expressions, but every time I look them up I can’t seem to find anything that is useable by me in WebMatrix.

I want to be able to test a password to be sure that it has both an uppercase and a lowercase number. In addition I need to check for at least one number.

UPDATE:
Okay, allow me to rephrase my question, maybe I am being confusing…

How does regex work in webmatrix razor (C#). Please show how the regex actually works (I can’t seem to find a clear, or even close to clear, answer on this on the web for webmatrix), then please show how it can be put (directly or indirectly) into if logic, on my cshtml page, so that I can actually check against it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:04:18+00:00Added an answer on June 12, 2026 at 11:04 pm

    A Regular Expression (Regex), as you will find out, is a tool used in matching text against a pattern and even extracting or replacing matches in the source text.

    To do this the Regex engine (which exists in the .Net framework inside the namespace System.Text.RegularExpressions) uses some established patterns that represent certain kinds of chars.

    To use a Regex, you pass it the pattern agains which a text will be tested and the text itself.

    For instance, the following snippet tests if there are lowercase letters in the text:

    using System.Text.RegularExpressions;
    ... 
    var Pattern = "[a-z]";
    if (Regex.IsMatch(SomeText, Pattern)) {
    //... there is at least one lower case char in the text
    }
    

    The pattern used above estates that we are interested in a range of chars from lowercase “a” to lowercase “z”.

    A pattern to require at least one lowercase letter, one digit and one uppercase letter could probably be something like

    @"[\d]+[a-z]+[A-Z]|[\d]+[A-Z]+[a-z]|[a-z]+[\d]+[A-Z]|[a-z]+[A-Z]+[\d]|[A-Z]+[\d]+[a-z]|[A-Z]+[a-z]+[\d]"
    

    As you can see, a Regex pattern can be as simple as in the first example, but may escalate fast in complexity depending on the kind of information you want to check or extract.

    In the Regex above, the items between square brackets are called character classes. The plus sign after an element is a quantifier, it indicates that the item may appear one or more times. Items separated by a vertical bar indicate alternatives. The “\d” pattern represents any digit from “0” to “9”.

    You don’t really need a Regex to check the password strength in your application, but using then instead of the explicit tests you are currently making would (in my opinion), greatly improve your program’s readability:

    using System.Text.RegularExpressions;
    ... 
    if (!Regex.IsMatch(password, "[A-Z]")) {
      errorMessage = "Your password must contain at least one uppercase character."; 
    } else if (!Regex.IsMatch(password, "[a-z]") {
      errorMessage = "Your password must contain at least one lowercase character."; 
    } else if (! Regex.IsMatch(password, @"[\d]")){
      errorMessage = "Your password must contain at least one numerical character."; 
    }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find a single regular expression that I can use to parse
Possible Duplicate: Use regular expressions to validate passwords I'm trying to code a php
I am trying use javascript regular expressions to do some matching and I found
I'm trying to use regular expressions to match a string that does not contain
I'm trying to use regular expressions in order to validate strings so before I
I am new to regular expressions, and I've been trying to use it with
I am trying to use Regular Expressions to decode some HTML I retrieve from
I'm trying to use regular expression right now and I'm really confuse. I want
I am trying to use a regular expression with grep command of Linux (^\s*\*\s*\[
I am in need of a regular expression that I can use to examine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.