Skip to content

Regular Expression | Leap Years and More

I’ve recently been looking for a regular expression to do some client side date checking, and I haven’t been able to find one that can satisfy the following criteria: Has a range from 1800 – Now Performs proper date checking with leap years MM/DD/YYYY Form Invalid Date Checking (These constr…

How to highlight text using javascript

Can someone help me with a javascript function that can highlight text on a web page. And the requirement is to – highlight only once, not like highlight all occurrences of the text as we do in case of search. Answer You can use the jquery highlight effect. But if you are interested in raw javascript co…

Generic deep diff between two objects

I have two objects: oldObj and newObj. The data in oldObj was used to populate a form and newObj is the result of the user changing data in this form and submitting it. Both objects are deep, ie. they have properties that are objects or arrays of objects etc – they can be n levels deep, thus the diff al…

How to start and stop/pause setInterval?

I’m trying to pause and then play a setInterval loop. After I have stopped the loop, the “start” button in my attempt doesn’t seem to work : Is there a working way to do this? Answer The reason you’re seeing this specific problem: JSFiddle wraps your code in a function, so start(…

Make a number a percentage

What’s the best way to strip the “0.”XXX% off a number and make it a percentage? What happens if the number happens to be an int? Answer A percentage is just: No need for anything fancy: