npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-turkey-validate

v1.0.5

Published

Türkiye'ye özel validasyon kuralları içeren React kütüphanesi

Downloads

59

Readme

react-turkey-validate

Adding quick verification to the forms used in Turkey

NPM JavaScript Style Guide

Install

npm install --save react-turkey-validate

Usage

Then, you can import and use the validators in your React components:

Basic Validators

import { 
  validateTCKimlik, 
  validateTelefon, 
  validateIBAN, 
  validateVergiNo, 
  validateSicilNo, 
  validateEmail,
  validateWebsite,
  validateDate
} from 'react-turkey-validate';

// TC Kimlik No validation
console.log(validateTCKimlik('12345678901')); // returns true or false

// Phone number validation
console.log(validateTelefon('05301234567')); // returns true or false

// IBAN validation
console.log(validateIBAN('TR330006100519786457841326')); // returns true or false

// Tax number validation
console.log(validateVergiNo('1234567890')); // returns true or false

// Registry number validation
console.log(validateSicilNo('1234567')); // returns true or false

// Email validation
console.log(validateEmail('[email protected]')); // returns true or false

// Website validation
console.log(validateWebsite('www.example.com')); // returns true or false

// Date validation
console.log(validateDate('2023-05-15')); // returns true or false
console.log(validateDate('15.05.2023', 'DD.MM.YYYY')); // returns true or false

Custom Validators

import { 
  createCustomValidator, 
  createLengthValidator,
  createNumberValidator
} from 'react-turkey-validate';

// Custom regex validator
const validatePostalCode = createCustomValidator(/^\d{5}$/);
console.log(validatePostalCode('34100')); // returns true
console.log(validatePostalCode('341')); // returns false

// Length validator
const validateUsername = createLengthValidator(3, 20);
console.log(validateUsername('user123')); // returns true
console.log(validateUsername('a')); // returns false (too short)
console.log(validateUsername('this_username_is_too_long')); // returns false (too long)

// Number validator
const validatePrice = createNumberValidator({ allowDecimal: true, maxDecimalPlaces: 2 });
console.log(validatePrice('123.45')); // returns true
console.log(validatePrice('123.456')); // returns false (too many decimal places)

Usage in React Components

Here's an example of how to use these validators in a React component:

import React, { useState } from 'react';
import { validateEmail, createLengthValidator } from 'react-turkey-validate';

const validateUsername = createLengthValidator(3, 20);

function RegistrationForm() {
  const [username, setUsername] = useState('');
  const [email, setEmail] = useState('');
  const [isUsernameValid, setIsUsernameValid] = useState(true);
  const [isEmailValid, setIsEmailValid] = useState(true);

  const handleUsernameChange = (e) => {
    const value = e.target.value;
    setUsername(value);
    setIsUsernameValid(validateUsername(value));
  };

  const handleEmailChange = (e) => {
    const value = e.target.value;
    setEmail(value);
    setIsEmailValid(validateEmail(value));
  };

  return (
    <form>
      <div>
        <input
          type="text"
          value={username}
          onChange={handleUsernameChange}
          placeholder="Username (3-20 characters)"
        />
        {!isUsernameValid && <p>Invalid username</p>}
      </div>
      <div>
        <input
          type="email"
          value={email}
          onChange={handleEmailChange}
          placeholder="Email"
        />
        {!isEmailValid && <p>Invalid email</p>}
      </div>
    </form>
  );
}

export default RegistrationForm;

This example demonstrates how to use both pre-defined validators (like validateEmail) and custom validators created with createLengthValidator in a React form.

License

MIT © ffatih-safak