Demo entry 1482311

regex_validation

   

Submitted by steve on Apr 08, 2015 at 19:03
Language: Python. Code size: 861 Bytes.

#########################################################################
# Format Checking 
import re

def regex_validate(pattern, input_str):
    """Format Checking
    
    Args:
      pattern (raw str): regex pattern that matches specific character 
                         combinations
      input_str (str): the string that will be subjected to validation
    
    Returns:
      bool: True if Valid, False otherwise

    """
    if isinstance(input_str, basestring):
        # if the input string matches to the regex Validate succeeds, 
        # otherwise Validation Fails
        is_valid = bool(re.match(pattern, input_str))
    else:
        # if the input is not a character sequence, Vailidation Fails
        is_valid = False
    return is_valid

#########################################################################

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).