Jorge Aguilar Jorge Aguilar - 1 year ago 63
PHP Question

HTML - Pattern to validate nomenclature

I'm trying to use the "pattern" attribute for HTML5 but I do not have much experience in the regex.

The nomenclature that I wish to validate is the following:


Where "0100455" will generally have 7 to 10 characters, "LM" may vary "LM, LI, AQ" and everything that comes after (eg "Izaguirre") is a text with at least 1 character.
What is important is that scripts are maintained and needed.

All this is necessary to validate a value that will then be modified in PHP and will later be pasted into a Word with PHPWord.

$sitebase = "0100455_LM_Izaguirre";
$string = explode("_", $sitebase);
$idcontrol = $string[1].'_'.$string[0];

Answer Source

^[0-9]{7,10}_[A-Z]{2}_[A-Za-z]+$ will bee the regex if LM will be any 2 charecters.

^[0-9]{7,10}_(LM|LI|AQ)_[A-Za-z]+$ will bee the regex if LM will only be {LM, LI, AQ}.


var rx = /^[0-9]{7,10}_(LM|LI|AQ)_[A-Za-z]+$/gm;

null will return for unmatching

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download