Tag Archives: Regular expression

Regular Expression is the combination of the some specific keywords and symbols that indicate the specific pattern for finding and replacing patterns of text. You can use the regular expression to search particular characters, words, or patterns of characters in the string.
  
See the example:
validating phone numbers in net
Remove invalid characters from string
Find and replace one date format to another
 
External Links:
MSDN

Example: test() and exec() methods of the RegExp in JavaScipt

We know that regular expression is just string pattern or simple string that describes the sequence of characters for searching something in the specified string. The test() method of any regular expression object returns the Boolean value that indicates whether or not the searched pattern exists in specified string. Continue reading Example: test() and exec() methods of the RegExp in JavaScipt

Replace one date format to another date format in the entire string using Regular expression.

You can use the Regex.Replace method to replace one date format to another date format in the entire string. The following code example uses the Regex.Replace method to replace dates that have the form mm/dd/yy with dates that have the form dd-mm-yy. Continue reading Replace one date format to another date format in the entire string using Regular expression.

How to remove invalid characters from a string using regular expression in c#

You can remove the set of the characters with the help of String.Remove method, but sometime this approach is not preferable by the developers, instead they use the regular expression for it. You can use the Regex.Replace method to strip some characters from the specified string. Continue reading How to remove invalid characters from a string using regular expression in c#

How to split single string into array of the strings through Regular expression in .net

The Following example shows how to split single string into array of the strings with the help of Regular expression in .net. We can split an input string into an array of substrings at the positions defined by a regular expression match.

Continue reading How to split single string into array of the strings through Regular expression in .net

Regular expression to check the currency upto 2 digit in JavaScript

 
Regular expression to check the currency upto 2 digit in JavaScript such as 34, 45.45, 567.45 etc.

    <html>  
      <head>  
          <script type="text/javascript">  
          var reg = /^\d+(\.\d\d)?$/;  
          function CurrencyValidation(Currency)
          {  
            var OK = reg.exec(Currency.value);  
            if (!OK)  
              window.alert("Currency isn't  valid");  
            else  
              window.alert("Currency is  valid");  
          }  
        </script>  
      </head>  
 
      <body>  
        <p>Enter your Currency up to two decimal numbers and then press Enter.</p>  
        <form action="">  
          <input name="txtCurrency" onchange="CurrencyValidation(this);">  
        </form>  
      </body>  
    </html>

Regular expression for password validation in JavaScript

 
Following example show that how we can validate password with the help of Regular Expression that have these validation:

Must be at least 10 characters
Must contain at least one one lower case letter,
one upper case letter,
one digit and one special character
Valid special characters are – @#$%^&+=

  <html>  
      <head>  
          <script type="text/javascript">  
          var reg = /^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$/;  
          function PhoneValidation(phoneNumber)
          {  
            var OK = reg.exec(phoneNumber.value);  
            if (!OK)  
              window.alert("phone number isn't  valid");  
            else  
              window.alert("phone number is  valid");  
          }  
        </script>  
      </head>  
 
      <body>  
        <p>Enter your phone number and then press Enter.</p>  
        <form action="">  
          <input name="txtPhone" onchange="PhoneValidation(this);">  
        </form>  
      </body>  
    </html>

More on Regular Expressions