C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » JavaScript »

Blank space validation


Posted Date: 30 Nov 2008      Posted By: balaji      Member Level: Silver     Points: 1   Responses: 5



Hai all,
i need to check a text box Value,the first character should not be a Space Character.how do i check in javascript.

Please anybody can help....






Responses

Author: King Cobra    30 Nov 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

Hi,


<script type ="text/javascript">
function dotandspace(txtboxvalue)
{
var flag=0;
var strText = txtboxvalue;
if (strText!="")
{
var strArr = new Array();
strArr = strText.split(" ");
for(var i = 0; i < strArr.length ; i++)
{
if(strArr[i] == "")
{
flag=1;
break;
}
}
if (flag==1)
{
alert("No space is allowed");
return false;
}
}
}

</script>
<script type="text/javascript" event="onblur" for="<%=txtBox.ClientID%>">
var vtxt = document.forms[0].<%=txtBox.ClientID%>;
var x=dotandspace(vtxt.value);
if(x==false)
{
txtBox.value ="";
txtBox.focus();
}
</script>


Cheers
King Cobra
Its Too Bad To Be Too Good



Author: Asal-2009    30 Nov 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 6

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type ="text/javascript">
function Check()
{
if(document.form1.TextBox1.value=="")
{
alert("First letter should not be blank");
document.form1.TextBox1.focus();
return false;
}
}

</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" onkeypress="Check()"></asp:TextBox>
</div>
</form>
</body>
</html>

G.Rajan
Happy New Year



Author: Arun Jacob    30 Nov 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 5

Call this javascript method in onkeypress event of textbox,


function ValidateOnKeyPress(pointer, e)
{
var code;
if (e)
code = e.keyCode;
else
code = window.event.keyCode;

var str = new String();
str = pointer.value;

if (code == 32 && pointer.value.length == 0)
{
alert("Validation Failed!!");
window.event.keyCode = 0;
}
}
}


Add attribute to textbox,


txtNumber.Attributes.Add("onkeypress", "return ValidateOnKeyPress(this,event);");


:-)

Arun Jacob
http://codepronet.blogspot.com/



Author: Radha Rani    01 Dec 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 4

HI,

You can check the first value whether it is space or not using Javascript.



var strName = txtName.value;

if (strName!="")
{
var strNameArr = new Array();
strNameArr= strName.split(" ");

if(strNameArr[0] == "")
{
flag=1;
break;
}
}
if (flag==1)
{
alert("Detected Space!");
return false;
}



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : How to add year or months from a given date using javascript
Previous : How to clear clipboard data in Mozilla
Return to Discussion Forum
Post New Message
Category: JavaScript

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use