Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

regex c# password numbers and letters

    private bool ValidatePassword(string password, out string ErrorMessage)
        {
            var input = password;
            ErrorMessage = string.Empty;

            if (string.IsNullOrWhiteSpace(input))
            {
                throw new Exception("Password should not be empty");
            }

            var hasNumber = new Regex(@"[0-9]+");
            var hasUpperChar = new Regex(@"[A-Z]+");
            var hasMiniMaxChars = new Regex(@".{8,15}");
            var hasLowerChar = new Regex(@"[a-z]+");
            var hasSymbols = new Regex(@"[!@#$%^&*()_+=[{]};:<>|./?,-]");

            if (!hasLowerChar.IsMatch(input))
            {
                ErrorMessage = "Password should contain at least one lower case letter.";
                return false;
            }
            else if (!hasUpperChar.IsMatch(input))
            {
                ErrorMessage = "Password should contain at least one upper case letter.";
                return false;
            }
            else if (!hasMiniMaxChars.IsMatch(input))
            {
                ErrorMessage = "Password should not be lesser than 8 or greater than 15 characters.";
                return false;
            }
            else if (!hasNumber.IsMatch(input))
            {
                ErrorMessage = "Password should contain at least one numeric value.";
                return false;
            }

            else if (!hasSymbols.IsMatch(input))
            {
                ErrorMessage = "Password should contain at least one special case character.";
                return false;
            }
            else
            {
                return true;
            }
        }
Comment

PREVIOUS NEXT
Code Example
Csharp :: list string to int c# 
Csharp :: c# get pixel color from image 
Csharp :: unique id c# 
Csharp :: list of chars to string c# 
Csharp :: delete file from FTP c# 
Csharp :: unity click on 2d object 
Csharp :: drag png to unity 3d 
Csharp :: c# datagridview change column name 
Csharp :: Xamarin.Forms - How to navigate to a tabbed page child page 
Csharp :: regular expression for website url validation in c# 
Csharp :: c# dictionary first 
Csharp :: hash password with salt c# 
Csharp :: how to get the position of a camera in unity 
Csharp :: wpf get screen size 
Csharp :: c# writeline list 
Csharp :: unity button press onclick click add C# 
Csharp :: new color unity 
Csharp :: initialize ConsoleLoggerProvider in EF core 
Csharp :: replace double backslash with single backslash c# 
Csharp :: unity hide mesh 
Csharp :: merge sort in c# 
Csharp :: linq distinct count 
Csharp :: .net Core Return File like File Server 
Csharp :: jump in unity 
Csharp :: remove comma from string c# 
Csharp :: c# socket connect timeout 
Csharp :: rotating an object in unity 
Csharp :: send type as argument c# 
Csharp :: c# byte array to file 
Csharp :: c# String.Concat() 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =