Day: January 14, 2018

how to count textarea characters using jquery?

If you want to count that which characters left in your textarea then you can use this code, in this code i need to count 99 and check which left when enter text in textarea. check this simple demo code.

<script>
$(document).ready(function() {
var text_max = 99;
$('#textarea_feedback').html(text_max + ' characters remaining');

$('#textarea').keyup(function() {
    var text_length = $('#textarea').val().length;
    var text_remaining = text_max - text_length;

    $('#textarea_feedback').html(text_remaining + ' characters remaining');
});

});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="textarea" rows="8" cols="30" maxlength="99" ></textarea>
<div id="textarea_feedback"></div>

this code check left characters ,if you need any help then please inform me.

Comment

how to validation Email JavaScript regular expression ?

In your html form most of the time need to check email validation. In this example you will learn simple email validation. First take a text input in html and a button input like this. this is demo code which validate email

 
<input type='text' id='txtEmail'/>
<input type='submit' name='submit' onclick='checkEmail();'/>
<script>
    function checkEmail() {
        var email = document.getElementById('txtEmail');
        var filter = /^(([^<>()\[\]\\.,;:\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,}))$/;
        if (!filter.test(email.value)) {
            alert('Please provide a valid email address');
            email.focus;
            return false;
        }
    }
</script>

this is another regular expression which use for email validation

 
<input type='text' id='txtEmail'/>
<input type='submit' name='submit' onclick='checkEmail();'/>
<script>
    function checkEmail() {

        var email = document.getElementById('txtEmail');
        var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

        if (!filter.test(email.value)) {
            alert('Please provide a valid email address');
            email.focus;
            return false;
        }
    }
</script>

hope it will help you, if you need any help then please inform me, i will try to help you

Comment

how can extract a file zip into a directory using php code?

If you want to extract a file into zip in a directory using php code then you can use this demo code which will work perfectly.Please check
this is demo code which help you to upload zip file and extract this zip in same file with zip folder also.

<?php
function rmdir_recursive($dir) {
    foreach(scandir($dir) as $file) {
        if ('.' === $file || '..' === $file) continue;
        if (is_dir("$dir/$file")) rmdir_recursive("$dir/$file");
        else unlink("$dir/$file");
    }
 
    rmdir($dir);
}
 
if(!empty($_FILES["file_name"]["name"])) {
    $filename = $_FILES["file_name"]["name"];
    $source = $_FILES["file_name"]["tmp_name"];
    $type = $_FILES["file_name"]["type"];
 
    $name = explode(".", $filename);
    $accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');
    foreach($accepted_types as $mime_type) {
        if($mime_type == $type) {
            $okay = true;
            break;
        }
    }
 
    $continue = strtolower($name[1]) == 'zip' ? true : false;
    if(!$continue) {
        $message = "The file you are trying to upload is not a .zip file. Please try again.";
    }
 
    $path = dirname(__FILE__).'/';  if you can check this path also  
    $filenoext = basename ($filename, '.zip');
    $filenoext = basename ($filenoext, '.ZIP');
 
    $targetdir = $path . $filenoext; 
    $targetzip = $path . $filename; 
    if (is_dir($targetdir))  rmdir_recursive ( $targetdir);
 
    mkdir($targetdir, 0777);
 
    if(move_uploaded_file($source, $targetzip)) {
        $zip = new ZipArchive();
        $x = $zip->open($targetzip);
        if ($x === true) {
            $zip->extractTo($targetdir.'/');
            $zip->close();
 
            unlink($targetzip);
        }
        $message = "Your file is uploaded and unpacked.";
    } else {
        $message = "There is a problem to upload.";
    }
}
 
?>
 
<?php if(isset($message)) echo "<p>$message</p>"; ?>
<form enctype="multipart/form-data" method="post" action="">
    <label>Upload a zip file to upload: <input type="file" name="file_name" /></label>
    <br />
    <input type="submit" name="submit" value="Upload" />
</form>

this is code first upload zip file then extract to folder. if you face any problem then please inform me. i will try to you.

Comment