validate-field


Namevalidate-field JSON
Version 2.0.1 PyPI version JSON
download
home_pagehttps://github.com/programspeaker/validate_field
SummaryValidate Field
upload_time2023-10-09 06:16:58
maintainerSarath Chandran
docs_urlNone
authorSarath Chandran
requires_python
licenseMIT
keywords validate_field
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            =======================

This is a project that is used to validate fields which is empty or it contain accurate values. Before touching the database we can check and raise appropriate error message if any mistmatch on it, else return True.

    1)  Check value is missed or empty
    2)  Check wether the datatype is correct or not
        2.1)    int = Specifies the integer value 
        2.2)    str = Specifies the string value
        2.3)    email = Specifies the email value
        2.4)    phone = Specifies the phone number value
        2.5)    alpha = Specifies the alphabetes value
        2.6)    '' = Specifies the null value, is equal to str
        2.7)    bool = Specifies the boolean value

Installing
=======================
    
    pip install validate-field

Usage
=======================
Enter received_field(values that comes from the front-end side) and required_field(list of values that need to be check in th back-end)

    from validate_field.validation import validate_field
    
    received_filed = {
        'id':1,
        'name':"testuser",
        'email':'testmail@gmail.com',
        'mobile':'+918330069872',
        'password':"testpass@122#",
        'is_active':True
    }
    required_filed = [
        ['id','int'],
        ['name','alpha'],
        ['email','email'],
        ['mobile','phone'],
        ['password','str'],
        ['is_active','bool']
    ]
   
    validation_result = validate_field(received_filed, required_filed)
    print(validation_result)
    
    Result
    ====================
    >> True
 

**Usecase 1** :- Check field is missing or not

Rule : name field is mandatory(required field)

Scenario : Avoid 'name' field

    received_field = {
        'id':1,
        'email':'testmail@gmail.com',
        'mobile':'+918330069872',
        'password':"testpass@122#",
        'is_active':True
    }
    required_field = [
        ['id','int'],
        ['name','alpha'],
        ['email','email'],
        ['mobile','phone'],
        ['password','str'],
        ['is_active','bool']
    ]
   
    validation_result = validate_field(received_field, required_field)
    print(validation_result)
    
    Result
    ====================
    >> name is not found
 

**Usecase 2** :- Check field is empty or not("")

Rule : name field is mandatory(required field)

Scenario : Avoid 'name' field value(name = "")

    received_field = {
        'id':1,
        'name':"",
        'email':'testmail@gmail.com',
        'mobile':'+918330069872',
        'password':"testpass@122#",
        'is_active':True
    }
    required_field = [
        ['id','int'],
        ['name','alpha'],
        ['email','email'],
        ['mobile','phone'],
        ['password','str'],
        ['is_active','bool']
    ]
   
    validation_result = validate_field(received_field, required_field)
    print(validation_result)
    
    Result
    ====================
    >> name is not found
 
 
**Usecase 3** :- Check integer field(int)

Rule : 'id' field only allow integer values

Scenario : Pass string value to the field 'id'

    received_field = {
        'id':"a",
        'name':"testuser",
        'email':'testmail@gmail.com',
        'mobile':'+918330069872',
        'password':"testpass@122#",
        'is_active':True
    }
    required_field = [
        ['id','int'],
        ['name','alpha'],
        ['email','email'],
        ['mobile','phone'],
        ['password','str'],
        ['is_active','bool']
    ]
   
    validation_result = validate_field(received_field, required_field)
    print(validation_result)
    
    Result
    ====================
    >> id is not an integer value
  
 
**Usecase 4** :- Check alpha field(alpha)

Rule : 'name' field only allow alphabetes
 
Scenario : Pass integer values along with the field 'name'

    received_field = {
        'id':1,
        'name':"testuser123",
        'email':'testmail@gmail.com',
        'mobile':'+918330069872',
        'password':"testpass@122#",
        'is_active':True
    }
    required_field = [
        ['id','int'],
        ['name','alpha'],
        ['email','email'],
        ['mobile','phone'],
        ['password','str'],
        ['is_active','bool']
    ]
   
    validation_result = validate_field(received_field, required_field)
    print(validation_result)
    
    Result
    ====================
    >> name is only allow alphabets
    
 
**Usecase 5** :- Check email field(email)

Rule : 'email' should be in correct format
 
Scenario : Pass incorrect format to the field 'email'

    received_field = {
        'id':1,
        'name':"testuser",
        'email':'testmail.com',
        'mobile':'+918330069872',
        'password':"testpass@122#",
        'is_active':True
    }
    required_field = [
        ['id','int'],
        ['name','alpha'],
        ['email','email'],
        ['mobile','phone'],
        ['password','str'],
        ['is_active','bool']
    ]
   
    validation_result = validate_field(received_field, required_field)
    print(validation_result)
    
    Result
    ====================
    >>email is not a valid email
 
 
**Usecase 6** :- Check phonenumber field(phone)

Rule : 'mobile' should be in correct format(Correct country code)
 
Scenario : Pass 'mobile' field with invalid country code +90

    received_field = {
        'id':1,
        'name':"testuser",
        'email':'testmail@gmail.com',
        'mobile':'+908330069872',
        'password':"testpass@122#",
        'is_active':True
    }
    required_field = [
        ['id','int'],
        ['name','alpha'],
        ['email','email'],
        ['mobile','phone'],
        ['password','str'],
        ['is_active','bool']
    ]
   
    validation_result = validate_field(received_field, required_field)
    print(validation_result)
    
    Result
    ====================
    >> mobile is not a valid phone number


**Usecase 7** :- Check phonenumber field(phone)

Rule : 'mobile' should be in correct format(Correct length)
 
Scenario : Pass 'mobile' field with invalid length +918330 or +918330069872333333


    received_field = {
        'id':1,
        'name':"testuser",
        'email':'testmail@gmail.com',
        'mobile':'+918330',
        'password':"testpass@122#",
        'is_active':True
    }
    required_field = [
        ['id','int'],
        ['name','alpha'],
        ['email','email'],
        ['mobile','phone'],
        ['password','str'],
        ['is_active','bool']
    ]
   
    validation_result = validate_field(received_field, required_field)
    print(validation_result)
    
    Result
    ====================
    >> mobile is not a valid phone number
 
 
**Usecase 8** :- Check string field(str)

Rule : 'password' field only allow string

Scenario : Pass 'password' field with integer value

    received_field = {
        'id':1,
        'name':"testuser",
        'email':'testmail@gmail.com',
        'mobile':'+918330069872',
        'password':123,
        'is_active':True
    }
    required_field = [
        ['id','int'],
        ['name','alpha'],
        ['email','email'],
        ['mobile','phone'],
        ['password','str'],
        ['is_active','bool']
    ]
   
    validation_result = validate_field(received_field, required_field)
    print(validation_result)
    
    Result
    ====================
    >> password is not a string value
  

If you are does not specify the field type, then the field type will be consider as **string**(str)
 
Scenario : Specify 'password' field type as " "

    received_field = {
        'id':1,
        'name':"testuser",
        'email':'testmail@gmail.com',
        'mobile':'+918330069872',
        'password':"testpass@122#",
        'is_active':True
    }
    required_field = [
        ['id','int'],
        ['name','alpha'],
        ['email','email'],
        ['mobile','phone'],
        ['password','']
    ]
 
 
Here password consider as string value.


**Usecase 9** :- Check boolean field(bool)

Rule : 'is_active' field allow only True or False.
 
Scenario : Pass any other values unless True or False.

    received_field = {
        'id':1,
        'name':"testuser",
        'email':'testmail@gmail.com',
        'mobile':'+918330',
        'password':"testpass@122#",
        'is_active':1
    }
    required_field = [
        ['id','int'],
        ['name','alpha'],
        ['email','email'],
        ['mobile','phone'],
        ['password','str'],
        ['is_active','bool']
    ]
   
    validation_result = validate_field(received_field, required_field)
    print(validation_result)
    
    Result
    ====================
    >> is_active is not a valid boolean value
 

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/programspeaker/validate_field",
    "name": "validate-field",
    "maintainer": "Sarath Chandran",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "sarath1plaza@gmail.com",
    "keywords": "validate_field",
    "author": "Sarath Chandran",
    "author_email": "programspeaker@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ef/45/d84181efecd898bba2ce324aeae0d4eba9eb761c1aea5d3c99915802fc44/validate_field-2.0.1.tar.gz",
    "platform": null,
    "description": "=======================\n\nThis is a project that is used to validate fields which is empty or it contain accurate values. Before touching the database we can check and raise appropriate error message if any mistmatch on it, else return True.\n\n    1)  Check value is missed or empty\n    2)  Check wether the datatype is correct or not\n        2.1)    int = Specifies the integer value \n        2.2)    str = Specifies the string value\n        2.3)    email = Specifies the email value\n        2.4)    phone = Specifies the phone number value\n        2.5)    alpha = Specifies the alphabetes value\n        2.6)    '' = Specifies the null value, is equal to str\n        2.7)    bool = Specifies the boolean value\n\nInstalling\n=======================\n    \n    pip install validate-field\n\nUsage\n=======================\nEnter received_field(values that comes from the front-end side) and required_field(list of values that need to be check in th back-end)\n\n    from validate_field.validation import validate_field\n    \n    received_filed = {\n        'id':1,\n        'name':\"testuser\",\n        'email':'testmail@gmail.com',\n        'mobile':'+918330069872',\n        'password':\"testpass@122#\",\n        'is_active':True\n    }\n    required_filed = [\n        ['id','int'],\n        ['name','alpha'],\n        ['email','email'],\n        ['mobile','phone'],\n        ['password','str'],\n        ['is_active','bool']\n    ]\n   \n    validation_result = validate_field(received_filed, required_filed)\n    print(validation_result)\n    \n    Result\n    ====================\n    >> True\n \n\n**Usecase 1** :- Check field is missing or not\n\nRule : name field is mandatory(required field)\n\nScenario : Avoid 'name' field\n\n    received_field = {\n        'id':1,\n        'email':'testmail@gmail.com',\n        'mobile':'+918330069872',\n        'password':\"testpass@122#\",\n        'is_active':True\n    }\n    required_field = [\n        ['id','int'],\n        ['name','alpha'],\n        ['email','email'],\n        ['mobile','phone'],\n        ['password','str'],\n        ['is_active','bool']\n    ]\n   \n    validation_result = validate_field(received_field, required_field)\n    print(validation_result)\n    \n    Result\n    ====================\n    >> name is not found\n \n\n**Usecase 2** :- Check field is empty or not(\"\")\n\nRule : name field is mandatory(required field)\n\nScenario : Avoid 'name' field value(name = \"\")\n\n    received_field = {\n        'id':1,\n        'name':\"\",\n        'email':'testmail@gmail.com',\n        'mobile':'+918330069872',\n        'password':\"testpass@122#\",\n        'is_active':True\n    }\n    required_field = [\n        ['id','int'],\n        ['name','alpha'],\n        ['email','email'],\n        ['mobile','phone'],\n        ['password','str'],\n        ['is_active','bool']\n    ]\n   \n    validation_result = validate_field(received_field, required_field)\n    print(validation_result)\n    \n    Result\n    ====================\n    >> name is not found\n \n \n**Usecase 3** :- Check integer field(int)\n\nRule : 'id' field only allow integer values\n\nScenario : Pass string value to the field 'id'\n\n    received_field = {\n        'id':\"a\",\n        'name':\"testuser\",\n        'email':'testmail@gmail.com',\n        'mobile':'+918330069872',\n        'password':\"testpass@122#\",\n        'is_active':True\n    }\n    required_field = [\n        ['id','int'],\n        ['name','alpha'],\n        ['email','email'],\n        ['mobile','phone'],\n        ['password','str'],\n        ['is_active','bool']\n    ]\n   \n    validation_result = validate_field(received_field, required_field)\n    print(validation_result)\n    \n    Result\n    ====================\n    >> id is not an integer value\n  \n \n**Usecase 4** :- Check alpha field(alpha)\n\nRule : 'name' field only allow alphabetes\n \nScenario : Pass integer values along with the field 'name'\n\n    received_field = {\n        'id':1,\n        'name':\"testuser123\",\n        'email':'testmail@gmail.com',\n        'mobile':'+918330069872',\n        'password':\"testpass@122#\",\n        'is_active':True\n    }\n    required_field = [\n        ['id','int'],\n        ['name','alpha'],\n        ['email','email'],\n        ['mobile','phone'],\n        ['password','str'],\n        ['is_active','bool']\n    ]\n   \n    validation_result = validate_field(received_field, required_field)\n    print(validation_result)\n    \n    Result\n    ====================\n    >> name is only allow alphabets\n    \n \n**Usecase 5** :- Check email field(email)\n\nRule : 'email' should be in correct format\n \nScenario : Pass incorrect format to the field 'email'\n\n    received_field = {\n        'id':1,\n        'name':\"testuser\",\n        'email':'testmail.com',\n        'mobile':'+918330069872',\n        'password':\"testpass@122#\",\n        'is_active':True\n    }\n    required_field = [\n        ['id','int'],\n        ['name','alpha'],\n        ['email','email'],\n        ['mobile','phone'],\n        ['password','str'],\n        ['is_active','bool']\n    ]\n   \n    validation_result = validate_field(received_field, required_field)\n    print(validation_result)\n    \n    Result\n    ====================\n    >>email is not a valid email\n \n \n**Usecase 6** :- Check phonenumber field(phone)\n\nRule : 'mobile' should be in correct format(Correct country code)\n \nScenario : Pass 'mobile' field with invalid country code +90\n\n    received_field = {\n        'id':1,\n        'name':\"testuser\",\n        'email':'testmail@gmail.com',\n        'mobile':'+908330069872',\n        'password':\"testpass@122#\",\n        'is_active':True\n    }\n    required_field = [\n        ['id','int'],\n        ['name','alpha'],\n        ['email','email'],\n        ['mobile','phone'],\n        ['password','str'],\n        ['is_active','bool']\n    ]\n   \n    validation_result = validate_field(received_field, required_field)\n    print(validation_result)\n    \n    Result\n    ====================\n    >> mobile is not a valid phone number\n\n\n**Usecase 7** :- Check phonenumber field(phone)\n\nRule : 'mobile' should be in correct format(Correct length)\n \nScenario : Pass 'mobile' field with invalid length +918330 or +918330069872333333\n\n\n    received_field = {\n        'id':1,\n        'name':\"testuser\",\n        'email':'testmail@gmail.com',\n        'mobile':'+918330',\n        'password':\"testpass@122#\",\n        'is_active':True\n    }\n    required_field = [\n        ['id','int'],\n        ['name','alpha'],\n        ['email','email'],\n        ['mobile','phone'],\n        ['password','str'],\n        ['is_active','bool']\n    ]\n   \n    validation_result = validate_field(received_field, required_field)\n    print(validation_result)\n    \n    Result\n    ====================\n    >> mobile is not a valid phone number\n \n \n**Usecase 8** :- Check string field(str)\n\nRule : 'password' field only allow string\n\nScenario : Pass 'password' field with integer value\n\n    received_field = {\n        'id':1,\n        'name':\"testuser\",\n        'email':'testmail@gmail.com',\n        'mobile':'+918330069872',\n        'password':123,\n        'is_active':True\n    }\n    required_field = [\n        ['id','int'],\n        ['name','alpha'],\n        ['email','email'],\n        ['mobile','phone'],\n        ['password','str'],\n        ['is_active','bool']\n    ]\n   \n    validation_result = validate_field(received_field, required_field)\n    print(validation_result)\n    \n    Result\n    ====================\n    >> password is not a string value\n  \n\nIf you are does not specify the field type, then the field type will be consider as **string**(str)\n \nScenario : Specify 'password' field type as \" \"\n\n    received_field = {\n        'id':1,\n        'name':\"testuser\",\n        'email':'testmail@gmail.com',\n        'mobile':'+918330069872',\n        'password':\"testpass@122#\",\n        'is_active':True\n    }\n    required_field = [\n        ['id','int'],\n        ['name','alpha'],\n        ['email','email'],\n        ['mobile','phone'],\n        ['password','']\n    ]\n \n \nHere password consider as string value.\n\n\n**Usecase 9** :- Check boolean field(bool)\n\nRule : 'is_active' field allow only True or False.\n \nScenario : Pass any other values unless True or False.\n\n    received_field = {\n        'id':1,\n        'name':\"testuser\",\n        'email':'testmail@gmail.com',\n        'mobile':'+918330',\n        'password':\"testpass@122#\",\n        'is_active':1\n    }\n    required_field = [\n        ['id','int'],\n        ['name','alpha'],\n        ['email','email'],\n        ['mobile','phone'],\n        ['password','str'],\n        ['is_active','bool']\n    ]\n   \n    validation_result = validate_field(received_field, required_field)\n    print(validation_result)\n    \n    Result\n    ====================\n    >> is_active is not a valid boolean value\n \n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Validate Field",
    "version": "2.0.1",
    "project_urls": {
        "Homepage": "https://github.com/programspeaker/validate_field"
    },
    "split_keywords": [
        "validate_field"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eee358e4e9d609b11d1b7cf7101be74a8acc2ec4563df4c04d6209ac1cd1ac9c",
                "md5": "9d6863f6114fcc2ffbd9d95aaad08ccd",
                "sha256": "76b0a031920284d6c047491776d59c57ef60c4c25a30ed8507760c77beb640df"
            },
            "downloads": -1,
            "filename": "validate_field-2.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9d6863f6114fcc2ffbd9d95aaad08ccd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4491,
            "upload_time": "2023-10-09T06:16:55",
            "upload_time_iso_8601": "2023-10-09T06:16:55.623463Z",
            "url": "https://files.pythonhosted.org/packages/ee/e3/58e4e9d609b11d1b7cf7101be74a8acc2ec4563df4c04d6209ac1cd1ac9c/validate_field-2.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ef45d84181efecd898bba2ce324aeae0d4eba9eb761c1aea5d3c99915802fc44",
                "md5": "5448933acf7d7e77fcf0afe4e9fdec84",
                "sha256": "bbba106f99c0da38d5ff5454910b3adbdb8e27994020d28622f2fb98934159ca"
            },
            "downloads": -1,
            "filename": "validate_field-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "5448933acf7d7e77fcf0afe4e9fdec84",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4390,
            "upload_time": "2023-10-09T06:16:58",
            "upload_time_iso_8601": "2023-10-09T06:16:58.485617Z",
            "url": "https://files.pythonhosted.org/packages/ef/45/d84181efecd898bba2ce324aeae0d4eba9eb761c1aea5d3c99915802fc44/validate_field-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-09 06:16:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "programspeaker",
    "github_project": "validate_field",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "validate-field"
}
        
Elapsed time: 0.39503s