Chaitanya Lakshmi
  • About Me
  • Job Duties
  • Knowledge Blog
  • Applications
  • Contact Us
    • Linked In
    • Facebook
  • About Me
  • Job Duties
  • Knowledge Blog
  • Applications
  • Contact Us
    • Linked In
    • Facebook

Regular Expression for Date Validation (YYYY-MM-DD)

2/24/2012

0 Comments

 
<?php
// Date Validation YYYY-MM-DD
$date = '2012-03/13';
if(preg_match("/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/", $date) === 0) {
    echo 'Date must be in : YYYY-MM-DD';
} else {
    echo "Date Correct";
}
?>
0 Comments

Regular Expression for Password Validation

2/24/2012

0 Comments

 
Password Criteria:

  1. Password must be at least 8 characters.
  2. Must contain at least one lower case letter
  3. One upper case letter
  4. One Digit
  5. One Special Character.

<?php
$password = "Password";
// Password Validation
if(preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[!@#$%^&*])(?=.*[A-Z]).*$/", $password) === 0) {
    echo '<p>1. Password must be at least 8 characters. <br>2. Must contain at least one lower case letter <br>3. One upper case letter <br>4. One Digit <br>5. One Special Character.</p>';
} else {
    echo "Password Strong";
}
?>
0 Comments

What are PHP Regular Expression Functions?

2/24/2012

0 Comments

 
  1. preg_match() ---> The preg_match() function searches string for pattern, returning true if pattern exists, and false otherwise.
  2. preg_match_all() ---> The preg_match_all() function matches all occurrences of pattern in string.
  3. preg_replace() ---> The preg_replace() function operates just like ereg_replace(), except that regular expressions can be used in the pattern and replacement input parameters.
  4. preg_split() ---> The preg_split() function operates exactly like split(), except that regular expressions are accepted as input parameters for pattern.
  5. preg_grep() ---> The preg_grep() function searches all elements of input_array, returning all elements matching the regexp pattern.
  6. preg_ quote() ---> Quote regular expression characters
0 Comments

Regular Expression Characterization?

2/24/2012

0 Comments

 
  1. a dollar sign ($) is used to match strings that end with the given pattern.
  2. a caret (^) character at the beginning of a regular expression indicates that it must match the beginning of the string.

  1. The dot (.) metacharacter matches any single character except newline (\).
  2. The vertical pipe (|) metacharacter is used for alternatives in a regular expression.

The metacharacters +, * and ? affect the number of times a pattern should be matched.

  1. '+' means Match one or more of the preceding expression
  2. '*' means Match zero or more of the preceding expression
  3. '?' means Match zero or one of the preceding expression

Curly braces {} can be used differently

  1. With a single integer, {n} means match exactly n occurrences of the preceding expression
  2. With one integer and a comma, {n,} means match n or more occurrences of the preceding expression
  3. With two comma-separated integers {n,m} means match the previous character if it occurs at least n times, but no more than m times

Regular Express with Respective Matches

  1. foo -------> Matches three letters or four numbersThe string "foo"
  2. ^foo -------> "foo" at the start of a string
  3. foo$ -------> "foo" at the end of a string
  4. ^foo$ -------> "foo" when it is alone on a string
  5. [abc] -------> a, b, or c
  6. [a-z] -------> Any lowercase letter
  7. [^A-Z] -------> Any character that is not a uppercase letter
  8. (gif|jpg) -------> Matches either "gif" or "jpeg"
  9. [a-z]+ -------> One or more lowercase letters
  10. [0-9\.\-] -------> Аny number, dot, or minus sign
  11. ^[a-zA-Z0-9_]{1,}$ -------> Any word of at least one letter, number or _
  12. ([wx])([yz]) -------> wy, wz, xy, or xz
  13. [^A-Za-z0-9] -------> Any symbol (not a number or a letter)
  14. ([A-Z]{3}|[0-9]{4}) -------> Matches three letters or four numbers
0 Comments

Email Id Validation in PHP?

2/24/2012

0 Comments

 
<?php
$email = "emailid@domain.com";
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
  echo "Valid email address.";
} else {
  echo "Invalid email address.";
}
?>
0 Comments

    Archives

    April 2012
    March 2012
    February 2012

    Categor

    All
    Ajax
    Api
    Cross Site Scripting
    Css
    Curl
    Design Patterns
    Drupal
    Exception Handling
    Htaccess
    Html
    Javascript
    Jquery
    Json
    Linux
    Mysql
    Oops
    Php
    Regular Expressions
    Web 2.0
    Webservices
    Wordpress
    Xhtml

    RSS Feed

Powered by Create your own unique website with customizable templates.