Update app.js

This commit is contained in:
Justin 2022-06-12 00:13:49 +08:00 committed by GitHub
parent 193b91583b
commit 5708986095
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1677,3 +1677,405 @@ function showWeatherP() {
document.getElementById('inputTextBtn7').disabled = false;
}
// Stocks validation
function stockValidate() {
var specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,<>\/?~]/;
let x = document.getElementById("inputText3").value;
let text;
if (x.toUpperCase() != x) {
document.getElementById('demo').style.display = "block";
text = "Stock symbol must be uppercase";
document.getElementById("inputText3").value = '';
// createLi = false;
}
else if (x === '') {
document.getElementById('demo').style.display = "block";
text = "No blanks"
// createLi = false;
}
else if (x.includes(' ')) {
text = "No spaces";
document.getElementById('demo').style.display = "block";
document.getElementById("inputText3").value = '';
// createLi = false;
}
else if (x.length > 5) {
document.getElementById('demo').style.display = "block";
text = "No more than 5 characters";
document.getElementById("inputText3").value = '';
// createLi = false;
}
else if (/\d/.test(x)) {
document.getElementById('demo').style.display = "block";
text = "No numbers allowed";
document.getElementById("inputText3").value = '';
// createLi = false;
}
// CAREFUL TO DELETE THE BACKEND LIST ITEMS, JUST DELETING THE VALUE LIKE THIS ISN"T 100% ACCURATE
else if (specialChars.test(x)) {
document.getElementById('demo').style.display = "block";
text = "No special characters allowed";
document.getElementById("inputText3").value = '';
// createLi = false;
}
else {
text = "Input OK";
document.getElementById('demo').style.display = "none";
createLi = true;
// CALL ADDING ITEMS FUNCTION SO THAT ONLY VALIDATED ITEMS CAN GET ADDED TO LIST
// addingItems();
setTimeout(
function() {
document.getElementById('inputText3').value="";
}, 100);
}
document.getElementById("demo").innerHTML = text;
}
// Crypto validation
function cryptoValidate() {
var specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|<>\/?~]/;
let x = document.getElementById("inputText4").value;
let baseCurrency = x.split(",")[1];
// console.log(baseCurrency)
let text;
if (x.toUpperCase() != x) {
document.getElementById('demo2').style.display = "block";
text = "Crypto and base must be uppercase";
document.getElementById("inputText4").value = '';
// createLi = false;
}
else if (x === '') {
document.getElementById('demo2').style.display = "block";
text = "No blanks"
// createLi = false;
}
else if (x.includes(' ')) {
text = "No spaces";
document.getElementById('demo2').style.display = "block";
document.getElementById("inputText4").value = '';
// createLi = false;
}
else if (specialChars.test(x)) {
document.getElementById('demo2').style.display = "block";
text = "No special characters allowed";
document.getElementById("inputText4").value = '';
// createLi = false;
}
else if (!x.includes(',')) {
document.getElementById('demo2').style.display = "block";
document.getElementById("inputText4").value = '';
text = "Missing ',' (e.g. BTC,USD)"
// createLi = false;
}
else if (!["USD","AUD","BTC","CAD","CHF","EUR","GBP","ETH","JPY","NZD"].includes(baseCurrency)) {
document.getElementById('demo2').style.display = "block";
document.getElementById("inputText4").value = '';
text = "Invalid base currency"
}
else {
text = "Input OK";
document.getElementById('demo2').style.display = "none";
createLi = true;
// CALL ADDING ITEMS FUNCTION SO THAT ONLY VALIDATED ITEMS CAN GET ADDED TO LIST
setTimeout(
function() {
document.getElementById('inputText4').value="";
}, 100);
}
document.getElementById("demo2").innerHTML = text;
}
// Forex validation
function forexValidate() {
var specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|<>\/?~]/;
let x = document.getElementById("inputText5").value;
let quoteCurrency = x.split(",")[1];
let baseCurrency = x.split(",")[0];
// console.log("base"+baseCurrency);
// console.log("quote"+quoteCurrency);
let text;
if (x.toUpperCase() != x) {
document.getElementById('demo3').style.display = "block";
text = "Base and quote must be uppercase";
document.getElementById("inputText5").value = '';
// createLi = false;
}
else if (x === '') {
document.getElementById('demo3').style.display = "block";
text = "No blanks"
}
else if (x.includes(' ')) {
text = "No spaces";
document.getElementById('demo3').style.display = "block";
document.getElementById("inputText5").value = '';
}
else if (/\d/.test(x)) {
document.getElementById('demo3').style.display = "block";
text = "No numbers allowed";
document.getElementById("inputText5").value = '';
}
// CAREFUL TO DELETE THE BACKEND LIST ITEMS, JUST DELETING THE VALUE LIKE THIS ISN"T 100% ACCURATE
else if (specialChars.test(x)) {
document.getElementById('demo3').style.display = "block";
text = "No special characters allowed";
document.getElementById("inputText5").value = '';
}
else if (!x.includes(',')) {
document.getElementById('demo3').style.display = "block";
document.getElementById("inputText5").value = '';
text = "Missing ',' (e.g. EUR,USD)"
}
else if (x.length > 7) {
document.getElementById('demo3').style.display = "block";
text = "No more than 7 characters";
document.getElementById("inputText5").value = '';
}
else if (!["USD","EUR","JPY","GBP","AUD","CAD","CHF","CNY","HKD","NZD","SEK","KRW","SGD","NOK","MXN","INR","RUB","ZAR","TRY","BRL",
"TWD","DKK","PLN","THB","IDR","HUF","ILS","CLP","PHP","AED","CZK","COP","SAR","MYR","RON","CLP","ARS","VND","QAR","KWD"].includes(baseCurrency)) {
document.getElementById('demo3').style.display = "block";
document.getElementById("inputText5").value = '';
text = "Invalid base currency"
}
else if (!["AED","AFN","ALL","AMD","AOA","ARS","AUD","AWG","AZN","BAM","BBD","BDT","BGN","BHD","BMD","BND","BOB","BRL","BSD", "BTN", "BWP", "BYN",
"BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR",
"FJD", "FKP", "FOK", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP",
"INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY","KES","KGS","KHR","KID","KMF","KRW","KWD", "KYD","KZT","LAK","LBP","LKR","LRD","LSL", "LYD",
"MAD","MDL","MGA","MKD","MMK","MNT","MOP","MRU","MUR","MVR","MWK","MXN","MYR","MZN","NAD","NGN","NIO","NOK","NPR","NZD","OMR","PAB","PEN",
"PGK","PHP","PKR","PLN","PYG","QAR","RON","RSD","RUB","RWF","SAR","SBD","SCR","SDG","SEK","SGD","SHP","SLL","SOS","SRD","SSP","STN","SYP","SZL",
"THB","TJS","TMT","TND","TOP","TRY","TTD","TVD","TWD","TZS","UAH","UGX","USD","UYU","UZS","VES","VND","VUV","WST","YER","ZAR"].includes(quoteCurrency)) {
document.getElementById('demo3').style.display = "block";
document.getElementById("inputText5").value = '';
text = "Invalid quote currency"
}
else {
text = "Input OK";
document.getElementById('demo3').style.display = "none";
createLi = true;
// CALL ADDING ITEMS FUNCTION SO THAT ONLY VALIDATED ITEMS CAN GET ADDED TO LIST
// addingItems();
setTimeout(
function() {
document.getElementById('inputText5').value="";
}, 100);
}
document.getElementById("demo3").innerHTML = text;
}
// Custom messages validation
function customMsgValidate() {
let x = document.getElementById("inputText13").value;
let y = document.getElementById("inputText14").value;
let text;
if ((x === '') && (y !== '')) {
createLi = false;
document.getElementById('demo4').style.display = "block";
text = "No blanks"
document.getElementById("inputText14").value = '';
document.getElementById('demo5').style.display = "none";
}
else if ((y === '') && (x !== '')){
createLi = false;
document.getElementById('demo5').style.display = "block";
document.getElementById("inputText13").value = '';
document.getElementById('demo4').style.display = "none";
text = "No blanks"
}
else if ((y === '') && (x === '')){
createLi = false;
document.getElementById('demo5').style.display = "block";
// document.getElementById("inputText13").value = '';
document.getElementById('demo4').style.display = "block";
text = "No blanks"
}
else if ((x !== '') && (y !== '')) {
text = "Input OK";
document.getElementById('demo4').style.display = "none";
document.getElementById('demo5').style.display = "none";
createLi = true;
// CALL ADDING ITEMS FUNCTION SO THAT ONLY VALIDATED ITEMS CAN GET ADDED TO LIST
// addingItems();
setTimeout(
function() {
document.getElementById('inputText13').value="";
document.getElementById('inputText14').value="";
}, 100);
}
document.getElementById("demo4").innerHTML = text;
document.getElementById("demo5").innerHTML = text;
}
// current weather validation
function currentWeatherValidate() {
var specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|<>\/?~]/;
let x = document.getElementById("inputText6").value;
let text;
if (specialChars.test(x)) {
document.getElementById('demo6').style.display = "block";
text = "No special characters allowed";
document.getElementById("inputText6").value = '';
}
else if (x === '') {
document.getElementById('demo6').style.display = "block";
text = "No blanks"
}
else if (/\d/.test(x)) {
document.getElementById('demo6').style.display = "block";
text = "No numbers allowed";
document.getElementById("inputText6").value = '';
}
else {
text = "Input OK";
document.getElementById('demo6').style.display = "none";
createLi = true;
// CALL ADDING ITEMS FUNCTION SO THAT ONLY VALIDATED ITEMS CAN GET ADDED TO LIST
// addingItems();
setTimeout(
function() {
document.getElementById('inputText6').value="";
}, 100);
}
document.getElementById("demo6").innerHTML = text;
}
// Daily forecast validation
function dailyWeatherValidate() {
var specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|<>\/?~]/;
let x = document.getElementById("inputText7").value;
let text;
if (specialChars.test(x)) {
document.getElementById('demo7').style.display = "block";
text = "No special characters allowed";
document.getElementById("inputText7").value = '';
}
else if (x === '') {
document.getElementById('demo7').style.display = "block";
text = "No blanks"
}
else if (/\d/.test(x)) {
document.getElementById('demo7').style.display = "block";
text = "No numbers allowed";
document.getElementById("inputText7").value = '';
}
else {
text = "Input OK";
document.getElementById('demo7').style.display = "none";
createLi = true;
// CALL ADDING ITEMS FUNCTION SO THAT ONLY VALIDATED ITEMS CAN GET ADDED TO LIST
// addingItems();
setTimeout(
function() {
document.getElementById('inputText7').value="";
}, 100);
}
document.getElementById("demo7").innerHTML = text;
}
// Commodities validation
function commoditiesValidate() {
var specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|<>\/?~]/;
let x = document.getElementById("inputText20").value;
let text;
if (x.toUpperCase() != x) {
document.getElementById('demo8').style.display = "block";
text = "Commodity symbol must be uppercase";
document.getElementById("inputText20").value = '';
// createLi = false;
}
else if (x === '') {
document.getElementById('demo8').style.display = "block";
text = "No blanks"
// createLi = false;
}
else if (x.includes(' ')) {
text = "No spaces";
document.getElementById('demo8').style.display = "block";
document.getElementById("inputText20").value = '';
// createLi = false;
}
else if (specialChars.test(x)) {
document.getElementById('demo8').style.display = "block";
text = "No special characters allowed";
document.getElementById("inputText20").value = '';
// createLi = false;
}
else if (!["ALU","BRENTOIL","LCO","COFFEE","XCU","CORN","COTTON","XAU","IRD","NI","XPD","XPT","XRH","RICE","RUTH","XAG","SOYBEAN",
"XDR","SUGAR","TIN","WHEAT","WTIOIL","ZNC","ETHANOL","CPO","NG","COCOA","ROBUSTA","LUMBER","RUBBER"].includes(x)) {
document.getElementById('demo8').style.display = "block";
document.getElementById("inputText20").value = '';
text = "Invalid commodity symbol"
}
else {
text = "Input OK";
document.getElementById('demo8').style.display = "none";
createLi = true;
// CALL ADDING ITEMS FUNCTION SO THAT ONLY VALIDATED ITEMS CAN GET ADDED TO LIST
setTimeout(
function() {
document.getElementById('inputText20').value="";
}, 100);
}
document.getElementById("demo8").innerHTML = text;
}