Advertisement
juliarnasution

script handle tanggal lahir

Dec 10th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.         const app = new Vue({
  3.             el:"#app",
  4.             data : {
  5.                 datebirth : ``,
  6.                 error_fields : ``,
  7.             },
  8.             methods :{
  9.                 handle_age() {
  10.                     // this.tanggal_lahir;
  11.                     let birthday = moment(this.datebirth);
  12.                     let date_now = moment(moment().format('YYYY-MM-DD'))
  13.                     const current_age = date_now.diff(birthday, 'years');
  14.  
  15.                     if (current_age > 27) {//usia mkasimal 27 tahun
  16.                         this.error_fields = "Maaf usia anda terlalu tua, batas usia maksimal adalah 27";
  17.                     } else if (current_age < 15) {//usia minimal 15 tahun
  18.                         this.error_fields = "Maaf usia anda terlalu muda, batas usia minimal adalah 15";
  19.                     } else {
  20.                         this.error_fields = ``;
  21.                     }                    
  22.                     return (isNaN(current_age))?0:current_age;
  23.                 },
  24.             }
  25.         });
  26.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement