Add method to JavaScript object

We can add a method to a JavaScript object. First, define a method and then assign that method as a property to an object. Example: <html> <body> <script> function stuClassName(className){ this.className=className; } function Student(name,rollNo){ this.name=name; this.rollNo=rollNo; this.stuClassName= stuClassName; } var student=new Student(“Jai”, “MCA/07/06”); student.stuClassName(“MCA Final”); document.write(“Name: ” +student.name + “</br>”); document.write(“RollNo: ” + student.rollNo + … Read more

Operator precedence in JavaScript

In every language, evaluation of an expression is done based on a predefined order of precedence which helps the language engine to determine which part of the expression will be evaluated first, which will second, and so on. Operator precedence in JavaScript Operator Operation Order of Precedence Order of Evaluation ++ Increment 1 R -> L … Read more

JavaScript IP address validation

IP address validation in JavaScript is used to ensure that the number entered in the specified IP address field should be a valid IP address. Regular Expression: /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) \.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ Example: <!DOCTYPE html> <html lang=”en”> <head> <script> function ipAddressCheck(ipAddress) { var regEx = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) \.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; if(ipAddress.value.match(regEx)) { return true; } else { alert(“Please enter a valid … Read more

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