Is Valid Email

by Javascript Specialist December 5, 2014 12:27
function isValidEmail(email) {
 var v = /^(([^<>()[\]\\.,;:\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,}))$/;
 return v.test(email);
}

Input Validation | JavaScript | References

Three ways to add Event Listeners in Javascript

by Javascript Specialist August 22, 2014 00:05
By adding event listeners, one will be able to transform the code form obtrusive to unobtrusive design.

Method 1: Directly adding using the "on" event

<input type='submit' value='Event Listeners' id='testListeners' /> <script>
document.getElementById('testListeners').onclick=function () {alert('Event Added'); }
</script>

Although this method is the simplest method, it has some drawback in terms of developing complex event listeners such as removing them and adding multiple events. 
Method 2: Using the AddEventLister method
<input type='submit' value='Event Listeners' id='testListener2'>
<script>
function alertEvent() {
alert('Event Listener Added');
}
var element=document.getElementById('testListener2');
if(element.addEventListener) element.addEventListener('click', alertEvent , false);
else if (element.attachEvent) { //for IE8 users
element.attachEvent("onclick", alertEvent);
</script>

This method more complete, but provides a full solution to complex algorithms such as stacking events and removing events.

Method 3: Using JQuery to bind events
I will not get into the details of this event because it is actually the slower of the previous methods. But you can conduct your own research as to whether this solution is worth looking into.

JavaScript | References | Tutorial

How to add an event listener to every cell in table

by Javascript Specialist August 12, 2014 22:30

When dealing with one element, it is easy to add the event, (onclick, onkeypress, onmouseover) directly to the element. However, when you are creating a dynamic table with lots of cells, then it becomes more work and waste resources to add so many events to every cell. So the short way is to create JavaScript function that can perform just that.


<table id='t'><tr><td>cell1</td><td>cell2</td><td>cell3</td></tr>
<tr><td>cell4</td><td>cell5</td><td>cell6</td></tr>
<tr><td>cell7</td><td>cell8</td><td>cell9</td></tr></table>

<script>
function alertEvent()
{
    alert('Event Added');
}

var c=document.getElementById('t').getElementsByTagName('td');
for (x=0;x<c.length;x++)
{
    c[x].onclick=alertEvent;
}
</script>

JavaScript | References | Tutorial

HTML Colour Codes, Names and Shades

by Javascript Specialist August 12, 2014 21:43

To get an understanding as to how these colours are generated, click here: Understanding HTML Colour Codes

Click on any cell to get the colour shades
white
#FFFFFF
255,255,255
ivory
#FFFFF0
255,255,240
lightyellow
#FFFFE0
255,255,224
yellow
#FFFF00
255,255,0
snow
#FFFAFA
255,250,250
floralwhite
#FFFAF0
255,250,240
lemonchiffon
#FFFACD
255,250,205
cornsilk
#FFF8DC
255,248,220
seashell
#FFF5EE
255,245,238
lavenderblush
#FFF0F5
255,240,245
papayawhip
#FFEFD5
255,239,213
blanchedalmond
#FFEBCD
255,235,205
mistyrose
#FFE4E1
255,228,225
bisque
#FFE4C4
255,228,196
moccasin
#FFE4B5
255,228,181
navajowhite
#FFDEAD
255,222,173
peachpuff
#FFDAB9
255,218,185
gold
#FFD700
255,215,0
pink
#FFC0CB
255,192,203
lightpink
#FFB6C1
255,182,193
orange
#FFA500
255,165,0
lightsalmon
#FFA07A
255,160,122
darkorange
#FF8C00
255,140,0
coral
#FF7F50
255,127,80
hotpink
#FF69B4
255,105,180
tomato
#FF6347
255,99,71
orangered
#FF4500
255,69,0
deeppink
#FF1493
255,20,147
fuchsia
#FF00FF
255,0,255
red
#FF0000
255,0,0
oldlace
#FDF5E6
253,245,230
lightgoldenrodyellow
#FAFAD2
250,250,210
linen
#FAF0E6
250,240,230
antiquewhite
#FAEBD7
250,235,215
salmon
#FA8072
250,128,114
ghostwhite
#F8F8FF
248,248,255
mintcream
#F5FFFA
245,255,250
whitesmoke
#F5F5F5
245,245,245
beige
#F5F5DC
245,245,220
wheat
#F5DEB3
245,222,179
sandybrown
#F4A460
244,164,96
azure
#F0FFFF
240,255,255
honeydew
#F0FFF0
240,255,240
aliceblue
#F0F8FF
240,248,255
khaki
#F0E68C
240,230,140
lightcoral
#F08080
240,128,128
palegoldenrod
#EEE8AA
238,232,170
violet
#EE82EE
238,130,238
darksalmon
#E9967A
233,150,122
lavender
#E6E6FA
230,230,250
lightcyan
#E0FFFF
224,255,255
burlywood
#DEB887
222,184,135
plum
#DDA0DD
221,160,221
gainsboro
#DCDCDC
220,220,220
crimson
#DC143C
220,20,60
palevioletred
#DB7093
219,112,147
goldenrod
#DAA520
218,165,32
orchid
#DA70D6
218,112,214
thistle
#D8BFD8
216,191,216
lightgrey
#D3D3D3
211,211,211
tan
#D2B48C
210,180,140
chocolate
#D2691E
210,105,30
peru
#CD853F
205,133,63
indianred
#CD5C5C
205,92,92
mediumvioletred
#C71585
199,21,133
silver
#C0C0C0
192,192,192
darkkhaki
#BDB76B
189,183,107
rosybrown
#BC8F8F
188,143,143
mediumorchid
#BA55D3
186,85,211
darkgoldenrod
#B8860B
184,134,11
firebrick
#B22222
178,34,34
powderblue
#B0E0E6
176,224,230
lightsteelblue
#B0C4DE
176,196,222
paleturquoise
#AFEEEE
175,238,238
greenyellow
#ADFF2F
173,255,47
lightblue
#ADD8E6
173,216,230
darkgray
#A9A9A9
169,169,169
brown
#A52A2A
165,42,42
sienna
#A0522D
160,82,45
yellowgreen
#9ACD32
154,205,50
darkorchid
#9932CC
153,50,204
palegreen
#98FB98
152,251,152
darkviolet
#9400D3
148,0,211
mediumpurple
#9370DB
147,112,219
lightgreen
#90EE90
144,238,144
darkseagreen
#8FBC8F
143,188,143
saddlebrown
#8B4513
139,69,19
darkmagenta
#8B008B
139,0,139
darkred
#8B0000
139,0,0
blueviolet
#8A2BE2
138,43,226
lightskyblue
#87CEFA
135,206,250
skyblue
#87CEEB
135,206,235
gray
#808080
128,128,128
olive
#808000
128,128,0
purple
#800080
128,0,128
maroon
#800000
128,0,0
aquamarine
#7FFFD4
127,255,212
chartreuse
#7FFF00
127,255,0
lawngreen
#7CFC00
124,252,0
mediumslateblue
#7B68EE
123,104,238
lightslategray
#778899
119,136,153
slategray
#708090
112,128,144
olivedrab
#6B8E23
107,142,35
slateblue
#6A5ACD
106,90,205
dimgray
#696969
105,105,105
mediumaquamarine
#66CDAA
102,205,170
cornflowerblue
#6495ED
100,149,237
cadetblue
#5F9EA0
95,158,160
darkolivegreen
#556B2F
85,107,47
indigo
#4B0082
75,0,130
mediumturquoise
#48D1CC
72,209,204
darkslateblue
#483D8B
72,61,139
steelblue
#4682B4
70,130,180
royalblue
#4169E1
65,105,225
turquoise
#40E0D0
64,224,208
mediumseagreen
#3CB371
60,179,113
limegreen
#32CD32
50,205,50
darkslategray
#2F4F4F
47,79,79
seagreen
#2E8B57
46,139,87
forestgreen
#228B22
34,139,34
lightseagreen
#20B2AA
32,178,170
dodgerblue
#1E90FF
30,144,255
midnightblue
#191970
25,25,112
aqua
#00FFFF
0,255,255
aqua
#00FFFF
0,255,255
springgreen
#00FF7F
0,255,127
lime
#00FF00
0,255,0
mediumspringgreen
#00FA9A
0,250,154
darkturquoise
#00CED1
0,206,209
deepskyblue
#00BFFF
0,191,255
darkcyan
#008B8B
0,139,139
teal
#008080
0,128,128
green
#008000
0,128,0
darkgreen
#006400
0,100,0
blue
#0000FF
0,0,255
mediumblue
#0000CD
0,0,205
darkblue
#00008B
0,0,139
navy
#000080
0,0,128
black
#000000
0,0,0

HTML | HTML Color | References