{"id":22770221,"url":"https://github.com/ujjwalguptaofficial/jsvalidator","last_synced_at":"2026-05-04T03:31:26.312Z","repository":{"id":57305786,"uuid":"88318261","full_name":"ujjwalguptaofficial/JsValidator","owner":"ujjwalguptaofficial","description":"Javascript library to validate different types of data with less lines of code.","archived":false,"fork":false,"pushed_at":"2017-09-13T05:41:13.000Z","size":49,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-07T04:45:28.487Z","etag":null,"topics":["javascript","javascript-library","javascriptvalidation","jsvalidator","validate-using-javascript","validators"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ujjwalguptaofficial.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-15T02:32:44.000Z","updated_at":"2017-04-16T12:33:20.000Z","dependencies_parsed_at":"2022-09-03T19:01:31.849Z","dependency_job_id":null,"html_url":"https://github.com/ujjwalguptaofficial/JsValidator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ujjwalguptaofficial%2FJsValidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ujjwalguptaofficial%2FJsValidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ujjwalguptaofficial%2FJsValidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ujjwalguptaofficial%2FJsValidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ujjwalguptaofficial","download_url":"https://codeload.github.com/ujjwalguptaofficial/JsValidator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246314125,"owners_count":20757457,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","javascript-library","javascriptvalidation","jsvalidator","validate-using-javascript","validators"],"created_at":"2024-12-11T15:29:27.945Z","updated_at":"2026-05-04T03:31:26.282Z","avatar_url":"https://github.com/ujjwalguptaofficial.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JsValidator\r\n\r\n# How to use \r\n1. download the file\r\n2. find the script under output folder\r\n3. include it in your html file\r\n\r\n# Doc\r\n\r\n## Check for null\r\n```\r\nvar Validator=new JsValidator();\r\nvar Name=document.getElementById('txtName');\r\nif(Validator.isInvalid(Name.value)) // return true if error otherwise false\r\n{\r\n    alert(Validator.ErrMsg); // Validator.ErrMsg will contains the current Error Message\r\n}\r\n\r\n```\r\n### Note :-  you can use \"isValid\" Function to check valid value.\r\n\r\n## Check for null with custom message\r\n\r\n```\r\nvar Validator=new JsValidator();\r\nvar Name=document.getElementById('txtName');\r\nif(Validator.isInvalid(Name.value,{Is:{Required:true,Msg:\"This is required value\"}})) \r\n{\r\n    alert(Validator.ErrMsg); \r\n}\r\n\r\n```\r\n\r\n## Check for different datatype -  email, url, mobile, number\r\n```\r\nvar Validator=new JsValidator();\r\nvar Price=document.getElementById('txtPrice');\r\n//check number\r\nif(Validator.isInvalid(Price.value,{ Type:'number'})) // return true if error otherwise false\r\n{\r\n    alert(Validator.ErrMsg); // Validator.ErrMsg will contains the current Error Message\r\n}\r\n\r\n//for email,url, mobile : replace type with the value like email,url,mobile - e.g -\r\n\r\nif(Validator.isInvalid(Price.value,{ Type:'email'})) // return true if error otherwise false\r\n{\r\n    alert(Validator.ErrMsg); // Validator.ErrMsg will contains the current Error Message\r\n}\r\n\r\n//Note :- the mobile no check is for indian no only. So in the case if something is not working for you - \r\n// you can override the validation logic or create your own.\r\n\r\n```\r\n### Note :- currently we support following datatype -\r\n1. Email\r\n2. Url\r\n3. Mobile\r\n4. Number\r\n\r\n## OverRide validation logic or add your own\r\n\r\n### Using Constructor\r\n```\r\nvar Validator=new JsValidator(\r\n    [\r\n        {\r\n            Type:'email',\r\n            Regex:/^((ht|f)tp(s?)\\:\\/\\/|~/|/)?([\\w]+:\\w+@)?([a-zA-Z]{1}([\\w\\-]+\\.)+([\\w]{2,5}))(:[\\d]{1,5})?((/?\\w+/)+|/?)(\\w+\\.[\\w]{3,4})?((\\?\\w+=\\w+)?(\u0026\\w+=\\w+)*)?/,\r\n            ErrorMsg:'Enter valid email',\r\n            Is:{Required:true,Msg:\"This field is required\"}\r\n        },\r\n        {\r\n            Type:'Mobile',\r\n            Code:function()\r\n            {\r\n                if(isNan(value))\r\n                {\r\n                    return true;\r\n                }\r\n                else if(value.toString().length\u003c10)\r\n                {\r\n                    return true;\r\n                }\r\n                return false;\r\n            },\r\n            ErrorMsg:'Enter valid number',\r\n            Is:{Required:false}\r\n        },\r\n        {\r\n            Type:'UsMobile', // this is for adding your own logic\r\n            Code:function(value)\r\n            {\r\n                //any code but return true or false\r\n            }\r\n        }\r\n    ]\r\n);\r\n\r\n// you can define both constraints like Code and Regex - if regex will return false then Code will be executed.\r\n\r\n```\r\n### Using 'setErrorDef' - you can define error at any time using this method\r\n\r\n```\r\nValidator.setErrorDef({\r\n            Type:'email',\r\n            Regex:/^((ht|f)tp(s?)\\:\\/\\/|~/|/)?([\\w]+:\\w+@)?([a-zA-Z]{1}([\\w\\-]+\\.)+([\\w]{2,5}))(:[\\d]{1,5})?((/?\\w+/)+|/?)(\\w+\\.[\\w]{3,4})?((\\?\\w+=\\w+)?(\u0026\\w+=\\w+)*)?/,\r\n            ErrorMsg:'Enter valid email',\r\n            Is:{Required:false}\r\n        });\r\n\r\n```\r\n\r\n## Check for Min or Max length\r\n```\r\nvar Validator=new JsValidator();\r\nvar Price=document.getElementById('txtPrice');\r\n//Min length\r\n// this will check for both number and value of min length 3 - Msg is optional\r\nif(Validator.isInvalid(Price.value,{ Type:'number',Min:{Length:3, Msg:\"Min length should be 3\"}})) \r\n{\r\n    alert(Validator.ErrMsg); // Validator.ErrMsg will contains the current Error Message\r\n}\r\n\r\n//Max length\r\n// this will check for both number and value of min length 3 - add Msg if you want the custom message\r\nif(Validator.isInvalid(Price.value,{ Type:'number',Max:{Length:3}})) \r\n{\r\n    alert(Validator.ErrMsg); // Validator.ErrMsg will contains the current Error Message\r\n}\r\n\r\n//Min and MAx both - add Msg in MinMax to get the custom message\r\nif(Validator.isInvalid(Price.value,{ Type:'number',MinMax:{Min:3,Max:5}}))\r\n{\r\n    alert(Validator.ErrMsg); // Validator.ErrMsg will contains the current Error Message\r\n}\r\n\r\n```\r\n## Check for Equal to\r\n\r\n```\r\nvar Validator=new JsValidator(),\r\nPwd=document.getElementById('txtPwd'),\r\nCPwd=document.getElementById('txtCPwd');\r\n\r\nif(Validator.isInvalid(CPwd.value,{Equal:{ To:Pwd.value,Msg:\"Confirm Pwd does not matches with Pwd\" } })\r\n{\r\n   alert(Validator.ErrMsg);\r\n}\r\n\r\n```\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fujjwalguptaofficial%2Fjsvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fujjwalguptaofficial%2Fjsvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fujjwalguptaofficial%2Fjsvalidator/lists"}