Quantcast
Channel: Joaquín Nuñez » php
Viewing all articles
Browse latest Browse all 6

Validar formato de patentes de autos en Chile con expresiones regulares

$
0
0

Esta expresión regular valida el formato antiguo y el nuevo de la patente de autos en Chile, ojo, sólo valida el formato. Usé como separador los caracteres . (punto), – (guión) ó un espacio.

Expresión regular

$patente = 'AB-12-34';
$regex = '/^[a-z]{2}[\.\- ]?[0-9]{2}[\.\- ]?[0-9]{2}|[b-d,f-h,j-l,p,r-t,v-z]{2}[\-\. ]?[b-d,f-h,j-l,p,r-t,v-z]{2}[\.\- ]?[0-9]{2}$/i';
if (preg_match($regex, $patente))
  echo "Patente correcta";
else
  echo "Patente incorrecta";

Método para jQuery plugin Validation

$.validator.addMethod("patente", function(value, element) {
  return this.optional(element) || value.match(/^[a-z]{2}[\.\- ]?[0-9]{2}[\.\- ]?[0-9]{2}|[b-d,f-h,j-l,p,r-t,v-z]{2}[\-\. ]?[b-d,f-h,j-l,p,r-t,v-z]{2}[\.\- ]?[0-9]{2}$/i);
}, "La patente ingresada no es valida.");

Validador patente symfony

<?php

/*
 * Copyright (c) 2010 José Joaquín Núñez (josejnv@gmail.com) http://joaquinnunez.cl/  
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-2.0.php)
 * Use only for non-commercial usage.
 *
 * Version : 0.1
*/


/**
 * sfValidatorPatente validates patentes chilenas.
 *
 * @package    symfony
 * @subpackage validator
 * @author     José Joaquín Núñez <josejnv@gmail.com>
 */


class sfValidatorPatente extends sfValidatorRegex
{
  const REGEX_PATENTE = '/^[a-z]{2}[\.\- ]?[0-9]{2}[\.\- ]?[0-9]{2}|[b-d,f-h,j-l,p,r-t,v-z]{2}[\-\. ]?[b-d,f-h,j-l,p,r-t,v-z]{2}[\.\- ]?[0-9]{2}$/i';

  /**
   * @see sfValidatorRegex
   */

  protected function configure($options = array(), $messages = array())
  {
    parent::configure($options, $messages);

    $this->setOption('pattern', self::REGEX_PATENTE);
  }
}

Saludos


Viewing all articles
Browse latest Browse all 6

Trending Articles


Girasoles para colorear


UPDATE SC IDOL: TWO BECOME ONE


Pokemon para colorear


tagalog love Quotes – Tiwala Quotes


The business quotes | Inspirational and Motivational Quotes for you


Long Distance Relationship Tagalog Love Quotes


5 Tagalog Relationship Rules


Re:Mutton Pies (lleechef)


Ka longiing longsem kaba skhem bad kaba khlain ka pynlong kein ia ka...


Vimeo 10.7.1 by Vimeo.com, Inc.


EASY COME, EASY GO


HOY PANGIT, MAGBAYAD KA!


Sapos para colorear


Smile Quotes


Patama lines and Tagalog Quotes Pinoy Sayings


Tropa Quotes


“Mali man na ikaw ay ibigin ko, akoy iibig padin sayo”


RE: Mutton Pies (frankie241)


Vimeo 10.7.0 by Vimeo.com, Inc.


FORECLOSURE OF REAL ESTATE MORTGAGE