New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@shagital/adonisjs-phone-validator

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shagital/adonisjs-phone-validator

Phone number validator for Adonisjs

1.0.2
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Adonisjs Phone Validator ▲

npm npm (scoped) NPM

Introduction

Adds phone number validation functionality to Adonisjs on the JS port of Google's libphonenumber API by catamphetamine

Step One - Install

Via Adonis CLI

adonis install @shagital/adonisjs-phone-validator

Via npm/yarn
  • Install package
// via npm
npm require @shagital/adonisjs-phone-validator

// via yarn
yarn add @shagital/adonisjs-phone-validator

Step Two - Register Provider

Open start/app.js and add @shagital/adonisjs-phone-validator/providers/PhoneValidatorProvider to the providers array

Usage

You use the phone validation syntax just like you'd normally do validation in Adonisjs. Examples below: NOTE: The country 2-character ISO code is required. You can find all supported codes here

controller method

//app/Controllers/Http/UserController

const { validate } = use('Validator')

class UserController {

  async store ({ request, session, response }) {
    const rules = {
      phone: 'required|phone:NG', // validate Nigerian phone number
    }

    const validation = await validate(request.all(), rules)

    if (validation.fails()) {
      session
        .withErrors(validation.messages())
     
      return response.redirect('back')
    }

    return 'Validation passed'
  }
}

Validator

//app/Validators/StoreUser.js

'use strict'

class StoreUser {
  get rules () {
    return {
      phone: 'required|phone:US', // validate a US phone number
    }
  }
}

Contribution

Free for all, if you find an issue with the package or think of an improvement, please send in a PR.

Keywords

adonisjs

FAQs

Package last updated on 23 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts