Pages

Wednesday, 3 July 2013

How To make jQuery Check Empty Value or Null Value OR Check if String Contains Null or Empty Value in C# Asp.Net

How To make jQuery Check Empty Value or Null Value OR Check if String Contains Null or Empty Value in C# Asp.Net


Program:

.Aspx File

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Check if string empty or null</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(function () {
        $('#btnCheck').click(function () {
            var txt = $('#txtName');
            if (txt.val() != null && txt.val() != '') {
                alert('you entered text ' + txt.val())
            }
            else {
                alert('Please enter text')
            }
        })
    });
</script>
</head>
<body>
<div>
Enter Text: <input type="text" id="txtName" />
<input type="button" id="btnCheck" value="Check" />
</div>
</body>
</html>

Live Demo:

Check if string empty or null
Enter Text:

No comments:

Post a Comment