Click here to Skip to main content
16,019,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
Am checking for input tag is empty.and if user try to enter only whitespaces it should get alert.but when i enter some text it giving same alert help me


What I have tried:

if(!$.trim($("#inputid").val())|| $("#inputid").val()=="" )
alert("input should not be empty");
return false;
Posted
Updated 22-Jul-16 0:27am

if($.trim($("#inputid").val()) == "")


<input type="text" id="inputid"/>
<script type="text/javascript">
    $(document).ready(function () {
        $("#inputid").blur(function () {
            if ($.trim($("#inputid").val()) == "") {
                alert("Enter text");
            }
        });
    });
</script>
 
Share this answer
 
v2
Comments
Member 12559011 22-Jul-16 6:16am    
when i type some text its giving same alert.
F-ES Sitecore 22-Jul-16 6:34am    
It works for me, the issue is probably elsewhere, I've updated my answer to add more context.
JavaScript
var value = $("#inputid").val().trim();
           if (value == '')
           {
               alert("input should not be empty");
               $("#inputid").val('').focus();
               return false;
           }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900