Coder Social home page Coder Social logo

regex's Introduction

Regular Expressions (RegEx)

Para que utilizar

Você pode usar o regex para verificar se um texto segue certo padrão, retornando true ou false para confirmar se um texto (string) está conforme deve estar

Retorno de boolean

Javascript

  const regexString = "/^([0-9... $/"
  const string = "abc123"
  var bool = regexString.test(string)

Java

  String regexString = "/^([0-9... $/";
  String string = "abc123";
  boolean allGood = string.matches(regexString);

Regex úteis

Dinheiro

/^(R\$\s?\d)(\,\d{2}|\.\d{2})?$/

Telefone

/^((\(\d{2}\)|\d{2})(\9\d{4}\-?\d{4}|[1-8]\d{3}\-?\d{4}))$/

CEP

/^(\d{5}\-?\d{3})$/

CPF

/^(\d{3}\.\d{3}\.\d{3}\-\d{2}|\d{3}\d{3}\d{3}\d{2})$/

CNPJ

/^(\d{2}\d{3}\d{3}\d{4}\d{2}|\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2})$/

Horário 24h

/^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/

Email

/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

URL Link

/^(https\:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/

ou

/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/

Data (dd/mm/yyyy)

/(^(((0[1-9]|1[0-9]|2[0-8])[\/](0[1-9]|1[012]))|((29|30|31)[\/](0[13578]|1[02]))|((29|30)[\/](0[4,6,9]|11)))[\/](19|[2-9][0-9])\d\d$)|(^29[\/]02[\/](19|[2-9][0-9])(00|04|08|12|16|20|24|28|32|36|40|44|48|52|56|60|64|68|72|76|80|84|88|92|96)$)/

regex's People

Contributors

mococa avatar

Watchers

 avatar

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.