{"id":27118353,"url":"https://github.com/lerhhl/js-textfield-validation","last_synced_at":"2025-07-10T15:36:05.399Z","repository":{"id":47968652,"uuid":"178830290","full_name":"lerhhl/js-textfield-validation","owner":"lerhhl","description":"An npm Package to validate textfield value.","archived":false,"fork":false,"pushed_at":"2022-12-30T18:40:57.000Z","size":220,"stargazers_count":3,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T10:33:52.141Z","etag":null,"topics":["javascript","javascript-library","textfield","textfield-validation","validation","validation-library"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/js-textfield-validation","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lerhhl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-01T09:31:15.000Z","updated_at":"2019-09-21T08:03:38.000Z","dependencies_parsed_at":"2023-01-31T13:15:19.980Z","dependency_job_id":null,"html_url":"https://github.com/lerhhl/js-textfield-validation","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/lerhhl%2Fjs-textfield-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lerhhl%2Fjs-textfield-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lerhhl%2Fjs-textfield-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lerhhl%2Fjs-textfield-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lerhhl","download_url":"https://codeload.github.com/lerhhl/js-textfield-validation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247615170,"owners_count":20967178,"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","textfield","textfield-validation","validation","validation-library"],"created_at":"2025-04-07T07:37:33.117Z","updated_at":"2025-04-07T07:37:33.595Z","avatar_url":"https://github.com/lerhhl.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Textfield Validation\n\nAn npm Package to validate textfield value.\n\n## How to install\n\n```bash\n# with npm\nnpm install js-textfield-validation\n```\n\n## API\n\nThere are chainable and non-chainable methods.\n\n### Available chainable validations\n\n| Methods | Description |\n| --- | --- |\n| `alphanumericOnly()` | To accept alphanumeric only. |\n| `dollarValue()` | To create a value with two decimal places. |\n| `ipAddress()` | To accept number and dot only. |\n| `noSpace()` | To remove all the spaces. |\n| `numOnly()` | To remove all the non integer. |\n| `removeNum()` | To remove all the number. |\n| `removeLeadingZero()` | To remove all the leading zero. |\n| `singleSpace()` | To accept single space between two characters only. |\n| `truncate(length: integer)` | To truncate the value to a specifc length. |\n| `wordOnly()` | To remove all non alphabet. |\n\n### Available non-chainable validations\n\n| Methods | Description | Output | Remark |\n| --- | --- | --- | --- |\n| `validateAlphanumericOnly(value: string)` | To check whether the value contains alphanumberic only. | `boolean` | nil |\n| `validateEmail(email: string)` | To check whether value is a valid email format. | `boolean` | nil |\n| `validateNRIC(nric: string)` | To check whether value is an valid NRIC in Singapore. | `boolean` | [Source](http://www.samliew.com/icval/) |\n| `validateIPAddress(address: string)` | To check whether value is a valid IP address. | `boolean` | nil |\n\n## HOW TO USE\n\n### Include chainable methods\n\n```JS\nimport Validation from \"js-textfield-validation\";\n```\n\n### Include non-chainable methods\n\n```JS\nimport { validateEmail, validateIPAddress, validateNRIC } from \"js-textfield-validation\";\n```\n\n### An example with ReactJS, material-ui and chainable methods\n\n```JS\nimport React, { Component } from \"react\";\nimport TextField from \"@material-ui/core/TextField\";\nimport Validation from \"js-textfield-validation\";\n\nclass App extends Component {\n  constructor() {\n    super();\n    this.state = {\n      name: \"\",\n      error: \"\",\n    };\n  };\n\n  handleChange = event =\u003e {\n    let validatedName = new Validations(event.target.value).removeNum().singleSpace();\n    if (validatedName.error !== \"\") {\n      this.setState({ name: validatedName.value, error: validatedName.error });\n    } else {\n      this.setState({ name: validatedName, error: \"\" });\n    }\n  };\n\n  render() {\n    return (\n      \u003cdiv\u003e\n        \u003cTextField\n          id=\"name\"\n          label\"Name\"\n          variant=\"outlined\"\n          placeholder=\"Enter your name here.\"\n          value={ this.state.name }\n          onChange={ this.handleChange }\n          helperText={ this.state.error }\n        /\u003e\n      \u003c/div\u003e\n    );\n  };\n};\n```\n\n### An example with ReactJS, material-ui and chainable and non-chainable methods\n\n```JS\nimport React, { Component } from \"react\";\nimport TextField from \"@material-ui/core/TextField\";\nimport Validation, { validateEmail } from \"js-textfield-validation\";\n\nclass App extends Component {\n  constructor() {\n    super();\n    this.state = {\n      email: \"\",\n      errorMessage: \"\"\n    };\n  };\n\n  handleChange = event =\u003e {\n    let newEmail = new Validation(event.target.value).noSpace().value;\n    const isValidEmail = validateEmail(newEmail);\n    if (isValidEmail) {\n      this.setState({ email: newEmail, errorMessage: \"\" })\n    } else {\n      this.setState({ email: newEmail, errorMessage: \"Invalid email\" })\n    }\n  };\n\n  render() {\n    return (\n      \u003cdiv\u003e\n        \u003cTextField\n          id=\"email\"\n          label\"Email\"\n          variant=\"outlined\"\n          placeholder=\"Enter your email here.\"\n          value={ this.state.email }\n          onChange={ this.handleChange }\n        /\u003e\n        \u003cdiv\u003e{ this.state.errorMessage }\u003c/div\u003e\n      \u003c/div\u003e\n    );\n  };\n};\n```\n\n## LICENSE\n\nLICENSE.md","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flerhhl%2Fjs-textfield-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flerhhl%2Fjs-textfield-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flerhhl%2Fjs-textfield-validation/lists"}