.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Regex: password must contain one number, one letter, and 0 or more special chars

Posted By:      Posted Date: September 28, 2010    Points: 0   Category :ASP.Net

I'm trying to validate a password, and I'm almost there, but need some help finishing it off. Here's what I need:

1) 6-10 characters

2) At least one alpha AND one number

3) The following special chars are allowed (0 or more): !@#$%

Here's what I have:


Passwords that should work: test1ng, abc123, abc1234567, 123abc, abc!123, !@#$%1abcd, !@#$%a9

Passwords that shouldn't work: a, 1, a1, 1$, %, abc!@#, 012345, a1234+, abcde, test*ng, abcde!, !@#$%!, a1234567890, testit!0987, 1abcdefghij

It works on all my test cases, except it allows "a1234567890", "testit!0987", and "1abcdefghij", none of which should be allowed, since they contain more than 10 chars. What am I missing?

View Complete Post

More Related Resource Links

Regex for checking number greater than 9

Hi All , I need to write a regex which can check for a number greater than equal to 9 .  

[regex] Extracting number preceding a particular text (in this case area unit).

Hi there, I'm looking for a regex to extract two numbers from the same text (they can be run independently, no need to extract them both in one go. I'm using yahoo pipes. Source Text: S$ 5,200 / month Negotiable, 1,475 sqft / 137 sqm (built-in) - Apartment, 10 Anson Road (D02) Need to extract as a number: 1,475 and also (but can be extracted on a separate instance) Need to extract as a number: 137 any guidance will be greatly appreciated. thanks in advance Paco

RegEx for strong password

Hi I need  RegEx expression for the following: Passwords must be at least eight characters including at least one number and one special character (punctuation, symbol or upper/lower case character).  Note: The  RegEx will be used in .NET   Thanks much!

SQL Server Maintenance Plan - Update Statistics fails if schema contains special chars


We have a database schema with a period in it's name.  This is valid as per http://msdn.microsoft.com/en-us/library/aa224033(SQL.80).aspx. When we create a maintenance plan to update statistics it will succeed if the object property is set to 'Tables and Views'. If this is set to 'Table' it will fail.

Steps to Reproduce

  • Create a new schema in a user database with a period in it's name, ie
    CREATE SCHEMA [Windows.EventLog] AUTHORIZATION [dbo]
  • Create a table with owner using schema created in #1, ie
    CREATE TABLE [Windows.EventLog].[Computer](
    	[ComputerId] [smallint] IDENTITY(1,1) NOT NULL,
    	[ComputerName] [varchar](255) NOT NULL,
    ) ON [PRIMARY]
  • Create a new maintenance plan, drag 'Update Statistics Task' to designer surface, edit properites, choose the user database, View T-SQL and test execution: it will work
  • Edit maintenance plan and modify 'Update Statistics Task', change Object to Table, change selection to all, execute task and it will fail. Also, if you now try to click 'View T-SQL' or change it back to 'Tables and Views', a error dialog with title 'Microsoft.SqlServer.MaintenancePlanTasksUI' shows will message 'Object

Regex match a number between 100 and 200 and no letters


Hello i`m new in regex and i relly need some help how to fin a solution in this problem

match a number between 100 and 200 inclusive and no letters allowed

Thx in advance hope some one will help me with this

Best regards


what is the "." for in a phone number regex?

      string phone = "973 555-7241";
      string pat = @"^\d{3}[- .]?\d{3}[- .]?\d{4}$";
      Match rv = Regex.Match(phone, pat);

What does the "." in the section "[- .]" of the above regex pattern mean?

I understand "." to mean 'any char but newline". Square brackets contain a set of chars, any of which can match the current character. [ -] means "either space char or dash char".  I read "[- .]" to mean any of "dash, space or any char other than new line".  But something like 973x555-1212 does not match the regex.



How to check for space in a password regex having multiple condition

I have a requirment where in the password field should accept all keys except space, it should have atleast one number , length should be 6 to 50
I tried following but did not work
1) Regex = @"^.*(?=.{6,50})(?=.*\d)(?=.*[a-zA-Z]).*$"

2) ^(?=[^\s])(?=[^\s]{6,50})(?=[^\s]*\d)(?=[^\s]*[a-zA-Z]).*$

Following are my test input text ( test case no 2 is having space at end)

ShouldNOT 654321-4
Should NOT654321-5
S houldNOT654321-6
ShouldNOT65432 1-7
S houldNOT 654321-9

Please help.

Thanks in Advance.
Rajendra Dewani

Regards Rajendra Dewani

how to use regex to identify the number of links in html source code


Hi, all, how to count the number of links in a piece of html source code, is it possible to use regex, for example, create a regex "href" and to count for matches? thanks in advance.

for example, a segment of html code like this:

<TD style="PADDING-RIGHT: 3px" width=150><A id=a588660 onclick="return Evar16_tracking('588660');" href="/products/shprodde.asp?sku=588940"><IMG style="BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc

"unexpected error has occurred" when user enters letter in column of type number

I am testing the form validation on my edit form.  The column is of type number.  When I typed in a letter, instead of presenting me with a validation error, I got "An unexpected error has occurred."  I refreshed the page, entered a letter again, and this time was presented with a validation error.  I'm afraid this sort of thing will happen to my end users once I move to production.  Any idea what might cause this?
There are no mistakes; every result tells you something of value about what your are trying to accomplish.

Regex for number seq. between 1 -16 eg: 1,2, 4-8,12


Can some one help about for the reular expression for a range of Numbers between 1 -16. The possibility of occurance of these numbers are like a printing document sequnce eg: 1, 2-10, 16 or 1, 4,  5-12 soon




Using RegEx, how to find substrings enclosed by a special character


Let’s say, special character is: $

Input string: This $abc$ and $def123$ is a test

Desired output:




I tried: @“\$.*?\$"


Got the output as:



RegExp Password without accent and special characters


Hi everyone,

I'm looking for an expression that corresponds to the following criterias:

  • Length must be at least 6 characters, no more than 10 characters,
  • Must include at least one upper case letter,
  • Must include at least one lower case letter,
  • Must include at least one numeric digit,
  • Special characters (like %, #, and so on...) are not allowed,
  • Accented characters (é, à, ï, and so on...) are not allowed.

Here is my expression : ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,10}$ It answers to the first four points above but not the last two ones. Does anybody has an idea to remove special and accented characters ?

Thank you so much for support.


How to Encrypt and Decrypt a Password using SQLSERVER 2005?(Video)

Encypt and Decrypt a Password using SQLSERVER 2005(Video)

symmetric key protected by a password

An alternative could be using a symmetric key protected by a password, as long as your application generates the CREATE SYMMETRIC KEY and OPEN SYMMETRIC KEY statements directly instead of calling them inside a SP (otherwise the password will still be passed as a parameter, and will be in clear in the profiler).

Convert English to Arabic number without changing any regional settings in .net

Well, most applications that I worked with was multilingual that supports English UI and Arabic UI.

And one of the major issue that we have faced is displaying Arabic numbers without the need of changing the regional settings of the PC.

So the code below will help you to display Arabic number without changing any regional settings.

dynamically adding sql server columns based on number of files in fileuploader


I want to create a new table to sql database at runtime.  The column names would be "Name", "Date", "Event".  I would also like to have one more column name "Image" but the problem is that since the amount of images will vary, I want the application to count the amount of files in the Multiple fileuploader and then add a image column to the table for the respected amount of files. 

For example if i am uploading 3 files in the multiple fileuploader, the names should be "Name", "Date", "Event", "Image1", "image2", Image3"

I also would like that table name to be name dynamically from the textbox Name when the user enters the information.


I have the following code to make a new table, but I dont know how to name the fields at runtime like previously asked please help!!!


Dim objConn As New SqlConnection("Server=<servername>;uid=<userid>;pwd=<password>;database=master")


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend