PHP Web Developer.

สิงหาคม 15, 2012

jQuery: Textbox Validation and the blur() Event

Filed under: Javascript & jquery — Prajak @ 6:04 pm

<b>Username:</b> <i>Username must be at least 4 characters in length</i>
<input type=”text” id=”txt_username” name=”username”>
<span id=”username_warning” style=”color:red”></span>
<b>Password:</b> <i>Password must be at least 6 characters in length</i>
<br><input type=”password” id=”txt_password” name=”password”>
<span id=”password_warning” style=”color:red”></span>

 

$(document).ready(function(){ 
    $("#txt_username").blur(function() 
    { 
        var username_length; 
 
        username_length = $("#txt_username").val().length; 
        $("#username_warning").empty(); 
 
        if (username_length < 4) 
            $("#username_warning").append("Username is too short"); 
    }); 
 
    $("#txt_password").blur(function() 
    { 
        var password_length; 
 
        password_length = $("#txt_password").val().length; 
        $("#password_warning").empty(); 
 
        if (password_length < 6) 
            $("#password_warning").append("Password is too short"); 
    }); 
}); 

How to allow only one decimal separator in the texbox?

Filed under: Javascript & jquery — Prajak @ 5:19 pm

$(‘.numeric_input’).live(“keyup”,function(){inputControl($(this),’int’);});
$(‘.float_input’).live(“keyup”,function(){inputControl($(this),’float’);});

function inputControl(input,format)
{
var value=input.val();
var values=value.split(“”);
var update=””;
var transition=””;
if (format==’int’){
expression=/^([0-9])$/;
finalExpression=/^([1-9][0-9]*)$/;
}
else if (format==’float’)
{
var expression=/(^\d+$)|(^\d+\.\d+$)|[,\.]/;
var finalExpression=/^([1-9][0-9]*[,\.]?\d{0,3})$/;
}
for(id in values)
{
if (expression.test(values[id])==true && values[id]!=”)
{
transition+=”+values[id].replace(‘,’,’.’);
if(finalExpression.test(transition)==true)
{
update+=”+values[id].replace(‘,’,’.’);
}
}
}
input.val(update);
}

การปัดเศษทศนิยมตำแหน่งที่2 (ลง)

Filed under: PHP — Prajak @ 4:45 pm

<?php
$number = 83.3259;

echo $number.'<BR>’;

$number1 = $number*100;
$number2 = floor($number1);
$number = $number2/100;

echo $number;

?>

===========================

83.3259

83.32

บลอกที่ WordPress.com .