w3resource

JavaScript : Download the validation Codes

This is the list of the validations discussed in our tutorials

You may download all the validation examples in a single zip file here. Alternatively, you may download those individually from the respective tutorial page.

  • Checking for non-empty
  • Checking for all letters
  • Checking for all numbers
  • Checking for floating numbers
  • Checking for letters and numbers
  • Checking string length
  • Email Validation
  • Date Validation
  • A sample Registration Form
  • Phone No. Validation
  • Credit Card No. Validation
  • Password Validation
  • IP address Validation



JavaScript: Tips of the Day

JavaScript: function and arguments

const person = {
  name: 'Lydia Hallie',
  hobbies: ['coding'],
};

function addHobby(hobby, hobbies = person.hobbies) {
  hobbies.push(hobby);
  return hobbies;
}

addHobby('running', []);
addHobby('dancing');
addHobby('baking', person.hobbies);

console.log(person.hobbies);

The addHobby function receives two arguments, hobby and hobbies with the default value of the hobbies array on the person object.
First, we invoke the addHobby function, and pass "running" as the value for hobby and an empty array as the value for hobbies. Since we pass an empty array as the value for y, "running" gets added to this empty array.
Then, we invoke the addHobby function, and pass "dancing" as the value for hobby. We didn't pass a value for hobbies, so it gets the default value, the hobbies property on the person object. We push the hobby dancing to the person.hobbies array.
Last, we invoke the addHobby function, and pass "bdaking" as the value for hobby, and the person.hobbies array as the value for hobbies. We push the hobby baking to the person.hobbies array.
After pushing dancing and baking, the value of person.hobbies is ["coding", "dancing", "baking"]

Ref: https://bit.ly/2Hcpkm6