Coder Social home page Coder Social logo

michaeldera / simple-regex-ts Goto Github PK

View Code? Open in Web Editor NEW
14.0 4.0 5.0 10.33 MB

A simple package with common regex patterns for Zimbabwe

Home Page: https://www.npmjs.com/package/simple-regex

License: MIT License

TypeScript 100.00%
regex zimbabwe regexp typescript npm-package npm npm-module

simple-regex-ts's Introduction

Simple Regex

npm version A simple package with common regex pattens for Zimbabwe

Links

Simple Regex Documentation

Github Repository

NPM Package

Installation

For npm users npm i simple-regex For yarn users yarn add simple-regex

Usage

To test a variable against a Regex expression:

SimpleRegex.MobileNumber.Econet.test(<your-variable>). This will return a boolean which indicates whether your variable matches the Regex Pattern.

You can also inject the Regex Pattern into HTML form fields. An example of this pattern in ReactJS <input type="text" name="number_plate" pattern={SimpleRegex.NumberPlate} title="Zimbabwean Number Plate">

Global Flag

Starting from version 2.0.0-alpha the package no longer has the global flag set by default. See an issue about it here

Available Patterns

SimpleRegex.MobileNumber.Econet Pattern for Econet Mobile Numbers

SimpleRegex.MobileNumber.Telecel Pattern for Telecel Mobile Numbers

SimpleRegex.MobileNumber.Netone Pattern for Netone Mobile Numbers

SimpleRegex.NumberPlate Pattern for Zimbabwean National Vehicle Registration Numbers

SimpleRegex.PassportNumber Pattern for Zimbabwean Passport Numbers

SimpleRegex.NationalId Pattern for Zimbabwean National Identification Numbers

SimpleRegex.EmailAddress Pattern for Email Addresses

SimpleRegex.DriversLicence Pattern for Zimbabwean Driver's Licences

SimpleRegex.SSN Pattern for Zimbabwean Social Security Number (NSSA)

SimpleRegex.DomainName Pattern for Zimbabwean domain name

simple-regex-ts's People

Contributors

dependabot[bot] avatar mashcom avatar michaeldera avatar nadchif avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

simple-regex-ts's Issues

[BUG] Validation of numbers with whitespace.

Describe the bug
If the number that needs to be tested contains whitespace, the regex tes will give a false result.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If possible include screenshots to help explain your problem.

Platform: Where did you see this bug (please remove those what does not apply):

  • Google Chrome
  • Safari
  • Microsoft Edge

Additional context
Please add any other context about the problem here (like the Operating System where you witnessed the bug)

Pattern to test MobileNumbers at once.

At the moment, testing if a value is a mobile number involves testing all three different RegExp SimpleRegex.MobileNumber.Econet.test(VALUE), SimpleRegex.MobileNumber.Netone.test(VALUE) and SimpleRegex.MobileNumber.Telecel.test(VALUE)...

A developer friendly way would be to have another single way to test all three line SimpleRegex.MobileNumber.test(VALUE), then all three can be can be tested at once.

Make the global flag optional

There are scenarios when the SimpleRegex tests will be run multiple times, for example, testing phone numbers during typing, after a user blurs input and just before sending an HTTP request to the server.

In these scenarios, the regex test return alternating results for the exact same phone number. After doing some digging (thanks to stack overflow), I realized that the global regex search starts from the previous match for each invocation of .test and that causes subsequent tests to have a different result even with the same input.

Example: Running SimpleRegex.MobileNumber.Econet.test(phoneNumber) twice, gives you different results

I would like to have an option to remove the global matching of the regexes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.