JSFiddle - React, Tailwind, and code Playground
by error454
JavaScript
var input = "http://www.google.com";
var input = "tel:555-555-1212";
var input = "[email protected]";
var input = "WIFI:S:mySSID;T:WPA2;P:password;;";
var input = "BEGIN:VCARD\nVERSION:2.1\nN:Gump;Forrest\nFN:Forrest Gump\nORG:Bubba Gump Shrimp Co.\nTITLE:Shrimp Man\nTEL;WORK;VOICE:(111) 555-1212\nTEL;HOME;VOICE:(404) 555-1212\nADR;WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America\nLABEL;WORK;ENCODING=QUOTED-PRINTABLE:100 Waters Edge=0D=0ABaytown, LA 30314=0D=0AUnited States of America\nADR;HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America\nLABEL;HOME;ENCODING=QUOTED-PRINTABLE:42 Plantation St.=0D=0ABaytown, LA 30314=0D=0AUnited States of America\nEMAIL;PREF;INTERNET:[email protected]\nREV:20080424T195243Z\nEND:VCARD";
parseURL(input);
parsePhone(input);
parseEmail(input);
parseWiFi(input);
parseVCard(input);
function parseURL(url) {
var url1 = /^http:\/\/.*/;
var url2 = /^www\..*/;
var url3 = /^https:\/\/.*/;
if (url1.test(url) || url2.test(url) || url3.test(url)) {
console.log("URL detected!");
}
};
function parsePhone(tel) {
var tel1 = /^tel:.*/;
if (tel1.test(tel)) {
console.log("Telephone number detected!");
}
};
function parseEmail(email) {
var email1 = /^\w{1,}@\w{1,}\.[a-zA-Z]{2,3}/;
if (email1.test(email)) {
console.log("Email detected!");
}
};
function parseWiFi(wifi) {
//WIFI:T:authentication;S:ssid;P:password;;
//T S and P sections may be in random order
var wifi1 = /^WIFI:/;
var wifi2 = /T:(\w{1,});/;
var wifi3 = /S:(\w{1,});/;
var wifi4 = /P:(\w{1,});/;
if (wifi1.test(wifi)) {
console.log("Found WiFi!");
if (wifi2.test(wifi)) {
console.log("Network type: " + wifi2.exec(wifi)[1]);
}
if (wifi3.test(wifi)) {
console.log("Network SSID: " + wifi3.exec(wifi)[1]);
}
if (wifi4.test(wifi)) {
console.log("Network Pass: " +...