Monday, June 17, 2013

Compare two time in javascript

Below is the function used to compare the two time using java scipt.


function checkTime(startTime, endTime) {
//compare two times are same or not....
if (Date.parse('17/06/2013 ' + endTime) - Date.parse('17/06/2013 ' + startTime) == 0) {
        alert('Both time cannot be same');
        return false;
    }
   else if (Date.parse('17/06/2013 ' + endTime) < Date.parse('17/06/2013 ' + startTime)) {
        alert('End time should be greater then Start time');
        return false;
    }
    return true;
}   

This function returns true if end time is greater than the start time. Otherwise it return false.
Instead of  '17/06/201' you can use any date. 


Wednesday, June 12, 2013

Time Validation in Java Script

This function validate the time format in 24 hours. 
function timeValidation(strTime) {
    if (strTime.indexOf(':') == -1 || strTime.length < 4 || strTime.length > 5) {
        return false;
    }
    var n = strTime.split(":");
    if (n.length > 2) {
        return false;
    }

    if (isNaN(n[0]) || n[0] > 23) {
        return false;
    }
    var minutePart = n[1].substring(0, 2);

    if (minutePart.length!=2 || isNaN(minutePart) || minutePart > 59) {
        return false;
    }    
    return true;

}

Wednesday, May 29, 2013

Website URL validation in Java Script

funtion WebsiteValidation(){
 var website = document.getElementById("<%=TxtWeb.ClientID %>").value.toLowerCase();
            if (website != "") {
                var websitePart = website.split(".");
                    if (websitePart.length > 2) {
                    if (websitePart[0] == "www" && websitePart[1].length > 1 && websitePart[websitePart.length - 1].length < 4 && websitePart[websitePart.length - 1].length > 1) {
                    }
                    else {
                        alert('Invalid website');
                        return false;
                    }
                }
                else {
                    alert('Invalid website');
                    return false;
                }
            }
}

Monday, May 27, 2013

Website URL validation in C#

 public bool UrlValidation(string websiteUrl)
    {                var websitePart = websiteUrl.Split('.');
                    if (websitePart.Length > 2) {
                    if (websitePart[0] == "www" && websitePart[1].Length > 1 && websitePart[websitePart.Length - 1].Length < 4 && websitePart[websitePart.Length - 1].Length > 1) {
                    return true;
                    }
                    else {
                      
                        return false;
                    }
                }
                else {
                   
                    return false;
                }
}

Friday, May 17, 2013

Remove Special Characters in SQL Server

Below is code:

Create Function [dbo].[RemoveNonAlphaCharacters]
(
   @Temp VarChar(1000)

Returns VarChar(1000) 
AS 
Begin 
 
    Declare @KeepValues as varchar(50) = '%[^a-z0-9]%' 
    While PatIndex(@KeepValues, @Temp) > 0 
        Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, '') 
 
    Return @Temp 
End