WEBLOG (4) WEBLOG – Page 4 – My IT experience

Javascript code to match 24 hour format hh:mm

Here is a simple Javascript time checker.

Javascript code:

$(document).ready(function() {
$("#checkTime").submit( function() {
if(!$("#timeElementId").val().match(/^([0-1][0-9]|2[0-3])(\D*)([0-5][0-9])$/))
{
var message = 'Time should be in the following format
' +
'hh:mm, hh:00-23, mm:00-59';
alert(message);
return false;
}
}
}

HTML code:

The expression inside the match function is good enough for a pattern within a html5 field validation.
Neat HTML5 code (at this moment not working with all browsers):


How to handle JSON request with PHP

There are some good tutorials which might help you send a JSON request via PHP cURL:
Getting jSON Data with PHP (curl method)

Here is a simple script that shows how to handle the JSON requests with PHP:

$stream = fopen('php://input', 'r');
$json = stream_get_contents($stream);
fclose($stream);       
$json = json_decode($json, true);

Simple PHP object to check for valid email

Here is a simple code for PHP that will help you check if a given string is a valid e-mail!

function checkEmail($email){
    $regularExpression="/^[a-z]+[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]+\.[a-zA-Z]{2,4}$/";
    if(preg_match($regularExpression, $email))
    {
        return "Valid";
    }

   return  "Not Valid";
}
$isValid = checkEmail("someone@email.com");

WordPress hacked – through get_footer funtction

Recently I have noticed that my wordpress blog was abused by spam links showing at the bottom of the page and beneath the sidebar.

After couple of tests I came to realise that the spam links where somehow embedded in the get_footer() function, which is called at the last line of your Main Index Template, Page Template and Single Post template. The function itself is located in wp-includes/general-template.php.

However the easiest way to get rid of the hacked get_footer is update your wordpress to the latest version or reinstall your current version. After completing this step it is strongly recommended that you change your passwords for accessing wp-admin and ftp.

Recover RAW drive to its Origin FAT or NTFS

A common problem is an external drive loosing its partition table information. As a result users get an message which asks them “Do you want to format this drive”.

If the drive is healthy there are several easy ways to recover your data.

Here is a very useful piece of free software which can help you, recover your files: http://www.cgsecurity.org/wiki/TestDisk_Download

The software is command line based. You should carefully read the instructions and follow them as the program executes.

Read More

Categories