Skip to content

Add Validation module #14

@Descent098

Description

@Descent098

The purpose of this module is to provide easy ways to validate strings are in the correct format for use.

TODO

  • Create a validation class that can take in a regex string, and has 2 methods: __repr__(), validate()
  • Add in the instances found in the Validation instances section

Validation class

import re
from dataclasses import dataclass

@dataclass
class Validator:
    validation_string:str

    def validate(self, value:str, as_bool:bool=False) -> :
        compiled_expression = re.compile(self.validation_string)
        if not as_bool:
            return compiled_expression.match(value) # Return full match groups
        else:
            return bool(compiled_expression.match(value))

    def __repr__(self) ->str:
        return self.validation_string

Validation instances

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions