From 2bcb8b87e6df2bc82ef0fa48ab9a94b3f225bb83 Mon Sep 17 00:00:00 2001 From: Rifjan Jundila Date: Mon, 31 Oct 2022 15:57:31 +0700 Subject: [PATCH] feat: regex email js --- Languages/Javascript/regex email/index.js | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Languages/Javascript/regex email/index.js diff --git a/Languages/Javascript/regex email/index.js b/Languages/Javascript/regex email/index.js new file mode 100644 index 00000000..85f8f3eb --- /dev/null +++ b/Languages/Javascript/regex email/index.js @@ -0,0 +1,33 @@ +function checkEmail(email) { + // let regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; + // let regex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/; + // let regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + let regex = /^[^ ]+@[^ ]+\.[a-z]{2,3}$/; + // let regex = /^([a-zA-Z0-9_\.\-])*\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; + // !!x || x === '' + if (typeof(email) != 'undefined') { + if (typeof(email) == 'string') { + if (email.match(regex)) { + return 'VALID' + }else{ + let regex2 = new RegExp('[a-z0-9]+@test'); + if (regex2.test(email)) { + return "INVALID" + }else{ + return "Error : Alamat email tidak sesuai" + } + } + }else{ + return "Error : Invalid data type" + } + }else{ + return "Error : Bro where is the parameter ? " + } + +} +console.log(checkEmail('apranata@test.co.id')); +console.log(checkEmail('apranata@test.com')); +console.log(checkEmail('apranata@test')); +console.log(checkEmail('apranata')); +console.log(checkTypeNumber(checkEmail(3322))); +console.log(checkEmail()); \ No newline at end of file