Package: vlight
vlightsimple package for validation dataGetting StartedInstallingif you have old version do this:pip uninstall vlightand to install latest version :pip install vlightuse vlightfromvlightimportvexamplesvalidate a simple login form with email :fromvlightimportvalid# also you can use "v" helper methodvlight in djangocreate validation rules and set datafromvlightimportvvalid=v({"email":"req|email","password":"req|min:8|max:255"},data={"email":"test@gmail.com","password":"123"# this field have minimum character error})#check data is validifvalid.isOk():# submit your formpasserror=valid.errors()#check have errorifvalid.fails():msgs=error.all()#check a field have erroriferror.has("email"):#this block run when your email field have errorpass#get field errors messagesprint(error.get("email"))# you can set returned error lengthprint(error.get("email",2))#customize error messages#to customize all fields default messages:valid=v({"email":"required|email","password":"required|min:8|max:255"},data={"email":"test@gmail.com","password":"123"},messages={"required":"{field}required ","email":"email field with value [{value}] not valid",})#or you can customize only a field messagesvalid=v({"email":"required|email""|required.msg:enter your email""|email.msg:email is not valid","password":"required|min:8|max:255""|str.min:your password is easy""|str.max:your selected password so hard"},data={"email":"test@gmail.com","password":"123"})an example in djangoviews.pyfrom django.shortcuts import render
from vlight import v

def index(request, **kwargs):
    msgs = []
    if request.method == "POST":

        valid = v({
            "email": "required|email",
            "password": "required|min:8|max:255"
        }, data=request.POST)

        if valid.fails():
            msgs = valid.errors().all()
        else:
            msgs.append("your form submitted!")

    return render(request, "index.html", {"login_errors": msgs})index.htmljinja2<form action="/" method="post">
    <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">
    <label for="email">email:</label>
    <input id="email" type="text" name="email">
    <br>
    <label for="password">password:</label>
    <input id="password" type="password" name="password">
    <input type="submit" value="login">
    {% for error in login_errors %}
        <li><a href="#">{{ error }}</a></li>
    {% endfor %}
</form>supported rulesrequiredcheck data has field and data is not empty"required"emailpattern :^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"email"ippattern :^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"ip"urlpattern :^http(s?):\/\/(www\.)?(((\w+(([\.\-]{1}([a-z]{2,})+)+)(\/[a-zA-Z0-9\_\=\?\&\.\#\-\W]*)*$)|(\w+((\.([a-z]{2,})+)+)(\:[0-9]{1,5}(\/[a-zA-Z0-9\_\=\?\&\.\#\-\W]*)*$)))|(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}(([0-9]|([1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]+)+)(\/[a-zA-Z0-9\_\=\?\&\.\#\-\W]*)*)((\:[0-9]{1,5}(\/[a-zA-Z0-9\_\=\?\&\.\#\-\W]*)*$)*))$"url"not_inincheck value in items"in:small,larg"regexnot_regexcoming soonextcheck path extension"ext:jpg,png,jpeg"intinteger validation"int"maxset maximum character of string"max:255"and you can change the rule for int value to check max integer value"int|max:255"[ more validation rules will added coming soon ]develop your ruledocs coming soonlatest version changes0.1fix bugscontacttelegram:https://t.me/Amir_s365gmail:amirrezasalimi0@gmail.comLicenseThis project is licensed under the MIT License