Skip to content

Instantly share code, notes, and snippets.

View attilaking's full-sized avatar

attilaking

  • Brisbane, Australia
View GitHub Profile
@attilaking
attilaking / emailValidate.js
Created May 20, 2020 10:39
[Validate email] email validations #email #validate
function ValidateEmail(mail) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)) {
return (true)
}
//alert("You have entered an invalid email address!")
return (false)
}
@attilaking
attilaking / numbersonly
Created May 20, 2020 10:38
Number input only #number #validate
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
@attilaking
attilaking / modal.js
Last active April 6, 2020 09:54
[CSS JS MODAL] Modal #modal #popup
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
/* MODAL*/
@attilaking
attilaking / binarygap.js
Created March 29, 2020 02:21
[count Binary gap of an integer] Binary gap count #binary #binary gap
function binaryGap(N) {
let str = N.toString(2);
let startPos;
let endPos;
let res = [];
res.push(0);
console.log(str)
for (let i = 1; i < str.length; i++) {
@attilaking
attilaking / callback.js
Created March 14, 2020 11:43
[Callback] Callback#callback
// add() function is called with arguments a, b
// and callback, callback will be executed just
// after ending of add() function
function add(a, b , callback){
document.write(`The sum of ${a} and ${b} is ${a+b}.` +"<br>");
callback();
}
// disp() function is called just
// after the ending of add() function
@attilaking
attilaking / promise.js
Created February 14, 2020 02:29
[Javascript promise] How to do javascript promise #callback #promise
let p = new Promise((resolve, reject) => {
var imgData = 'data'; // this is always true
if (imgData) {
// This happens when the imgData returns true
resolve('Resolved');
}
else {
// This happens when imgData returns false;