phone number validation JavaScript JS

Phone number validation in JavaScript is used to make sure that all the numbers entered in the specified phone number field should be a valid phone number Regular Expression: /^\+(?:[0-9] ?){6,14}[0-9]$/ Example: <!DOCTYPE html> <html lang=”en”> <head> <script> function phoneNumberCheck(phoneNumber) { var regEx = ^\+{0,2}([\-\. ])?()?([\-\. ])??([\-\. ])?\d{3}([\-\. ])?\d{4}; if(phoneNumber.value.match(regEx)) { return true; } else … Read more

JavaScript string length validation

String length validation in JavaScript is used to make sure that the number of characters entered in a specified field will be restricted. For example, the name field should have a length of 8-10 characters only. Example: <!DOCTYPE html> <html lang=”en”> <head> <script> function stringLengthCheck(name, minlength, maxlength) { var mnlen = minlength; var mxlen = … Read more

alphanumeric validation JavaScript JS

Alphanumeric validation in JavaScript is used to make sure that all the characters entered in the specified field must be any alphabet (A-Z or a-z) or any number (0-9). Regular Expression: /^[0-9a-zA-Z]+$/ Example: <!DOCTYPE html> <html lang=”en”> <head> <script> function lettersNumbersCheck(name) { var regEx = /^[0-9a-zA-Z]+$/; if(name.value.match(regEx)) { return true; } else { alert(“Please enter … Read more

JavaScript alphabets and spaces validation

Spaces and Letters or alphabets-only validation in JavaScript is used to make sure that all the characters entered in the specified field must be any character from A-Z or a-z or white space. Regular Expression: /^[a-z][a-z\s]*$/ Example: <!DOCTYPE html> <html lang=”en”> <head> <script> function lettersAndSpaceCheck(name) { var regEx = /^[a-z][a-z\s]*$/; if(name.value.match(regEx)) { return true; } … Read more

JavaScript alphabets validation

Letters or alphabets-only validation in JavaScript is used to make sure that all the characters entered in the specified field must be any character from A-Z or a-z. Regular Expression: /^[A-Za-z]+$/ Example: <!DOCTYPE html> <html lang=”en”> <head> <script> function lettersOnlyCheck(name) { var regEx = /^[A-Za-z]+$/; if(name.value.match(regEx)) { return true; } else { alert(“Please enter letters … Read more

not empty validation JavaScript JS

Not empty or blank field validation is used to check whether anything is entered in a given field or not. It will check for null and zero-length strings. Example: <!DOCTYPE html> <html lang=”en”> <head> <script> function notEmptyCheck(name) { if (name.value.length == 0) { alert(“Name can not be empty.”); return false; } return true; } </script> … Read more

JavaScript Map values() method

The JavaScript map values() method is used to retrieve an object of Map iterator that contains the values for each element. Syntax: mapObj.values() Return: An object of Map iterator. Example: <!DOCTYPE html> <html> <body> <script> var map=new Map(); map.set(‘a’,”GOOD MORNING”); map.set(‘b’,”GOOD AFTERNOON”); map.set(‘c’,”GOOD EVENING”); map.set(‘d’,”GOOD NIGHT”); var itr= map.keys(); for(i=0;i<map.size;i++){ document.writeln(itr.next().value+”<br>”); } </script> </body> </html>

JavaScript Map set() method

The JavaScript map set() method adds a new or modifies the already existing key-value pairs to Map object. Syntax: mapObj.set(key,value) Parameters: key: It represents the key of the newly added map object. value: It represents the value of the newly added map object. Return: Updated map object. Example: <!DOCTYPE html> <html> <body> <script> var map=new … Read more

JavaScript Map keys() method

The JavaScript map keys() method is used to retrieve an object of the Map iterator that contains the keys for each element. Syntax: mapObj.keys() Return: An object of Map iterator. Example: <!DOCTYPE html> <html> <body> <script> var hello=new Map(); hello.set(‘a’,”GOOD MORNING”); hello.set(‘b’,”GOOD AFTERNOON”); hello.set(‘c’,”GOOD EVENING”); hello.set(‘d’,”GOOD NIGHT”); var array= hello.keys(); document.writeln(array.next().value+”<br>”); document.writeln(array.next().value+”<br>”); document.writeln(array.next().value+”<br>”); document.writeln(array.next().value); </script> … Read more

JavaScript Map has() method

The JavaScript map has() method is used to indicate whether the map object contains the specified key element. Syntax: mapObj.has(key) Parameters: key: It represents the specific key that has to be searched. Return: Returns true if the specified key is present in the map otherwise returns false. Example: <!DOCTYPE html> <html> <body> <script> var hello=new … Read more