10 examples of 'jquery phone number validation with country code' in JavaScript

Every line of 'jquery phone number validation with country code' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
123function InvalidPhone(){
124 var invalid_phone_number = $("#invalid-phone-number");
125 invalid_phone_number.attr("attrHidden", "false");
126 var need_phone_number = $("#need-phone-number");
127 need_phone_number.attr("attrHidden", "true");
128 window.phone_ok = false;
129}
40function isValidPhone(value) {
41 return /^[0-9]+$/ig.test(value)
42}
35function validateZIPCode(value){
36 if (!isZIPCode(value)) {
37 alert("Please enter a ZIP code in the form xxxxx.");
38 };
39}
21export function isValidLength(phone: string): boolean {
22 return phone.length >= PHONE_MIN_LENGTH && phone.length <= PHONE_MAX_LENGTH;
23}
269static phone(value) {
270 var reg = /^((\d{10,11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/;
271 return reg.test(value);
272}
39function validateZipCode(inputField, helpText) {
40 // First see if the input value contains data
41 if (!validateNonEmpty(inputField, helpText))
42 return false;
43
44 // Then see if the input value is a ZIP code
45 return validateRegEx(/^\d{5}$/,
46 inputField.value, helpText,
47 "Please enter a 5-digit ZIP code.");
48}
210function getPhoneCode(){
211 return $("#phoneNumber").val();
212}
28export function phoneValidator(rule, value, callback) {
29 const INVALID_PHONE_MSG = 'Número de telefone inválido';
30 const PHONE_REGEX = /^\([0-9]*\)\s*[0-9]*\s*-*\s*[0-9]*/i;
31
32 if (!rule.required && !value) {
33 callback();
34 }
35
36 if (PHONE_REGEX.test(value)) {
37 callback();
38 } else {
39 callback(INVALID_PHONE_MSG);
40 }
41}
42public getDigits(phone: string): string {
43 const numbers = phone.match(/\d+/g)
44 if (numbers === null) return ''
45 return numbers.join('')
46}
22ngOnInit() {
23 this.validator = phone(this.phone);
24}

Related snippets