I use this:
jQuery.validator.addMethod("regex2", function(value, element, param) { return value.match(new RegExp("." + param + "$")); }); $("#phonenumber").rules("add", { regex2: "[0-9]+"})
to check the phone. The phone number must be at least 7 digits, I received this regular expression from elsewhere and use the parameter minlength=7, but this is clearly unsuitable. How to do it?
minlength=7
I live in Venezuela. Therefore, I think it is useless . How can I change it? In my country, 0416-414 33 44 should be considered as a valid input for a phone number.
, , (, , +, -, ., ext) , 7.
+
-
.
ext
$.validator.addMethod('phone', function(value, element) { return this.optional(element) || (/^\d{7,}$/).test(value.replace(/[\s()+\-\.]|ext/gi, '')); });
<input class="phone">.
<input class="phone">
, :
"[0-9]+" "[0-9]{7,}\s*$".
"[0-9]+"
"[0-9]{7,}\s*$"
, "." "^".
"."
"^"
, \s? $ :
\s?
$
return value.match(new RegExp("." + param + "$"));
? *
. ? , ^, $: , .
^
, . . :
// Trim value before matching against regex. return jQuery.trim(value).match(new RegExp("^" + param + "$")); // Allow spaces at beginning or end with " *" (space + asterisk). return value.match(new RegExp("^ *" + param + " *$"));
, , , param.
param
// Add parentheses for robustness. return jQuery.trim(value).match(new RegExp("^(?:" + param + ")$"));
, , , , this|that. ^(this|that)$, ^this|that$, (^this)|(that$).
this|that
^(this|that)$
^this|that$
(^this)|(that$)
Source: https://habr.com/ru/post/1764265/More articles:Can you change a row in PostgresSQL? - postgresqlImageView scaling - androidSource fonts and terminal fonts - htmlHow to use ThreadSafeClientConnManager.requestConnection (HttpRoute route, object state) - androidThemes, Processes and Application.Exit () - multithreadingWhy does .png converted from gnuplot postcript output have a transparent background? - transparencyInvalid ASP.NET element name StartTag error - asp.netreading zipx in java - javaTransparency draws connection layers instead of redrawing - c #Aapt problem: resource identifier found for the attribute 'class' in the package 'android' - androidAll Articles