Solved

validate if a textbox in a datagrid allows any special symbols other than "|"(pipe)  to be entered using javascript

Posted on 2008-10-28
11
370 Views
Last Modified: 2012-05-05
Hi!

I have a datagrid.I have a textbox in one of the columns  in the datagrid.
The textbox should allow numbers and  a "|". it should not allow any special characters other than pipe.(|)
The validation ha sto be done using javascript.(not by using validation controls)
I need it ASAP.

IT'S EXTREMELY URGENT.

CAN I GET THE CODE/LOGIC FOR THAT asap.

thanks  a million in advance.
0
Comment
Question by:amukta
  • 6
  • 5
11 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 22828751
try:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<title></title>
<script type="text/javascript">
function validate(o){
	if( /[^\d|]/.test(o.value) )
	{
		alert("Invalid char found. Only digits and | are allowed.");
		setTimeout(function(){focusIt(o)},10);
	return false;
	}
return true;
}
function focusIt(o){
	o.focus();
}
</script>
</head>
<body>
<input type="text" onchange="validate(this)"/>
</body>
</html>

Open in new window

0
 

Author Comment

by:amukta
ID: 22828908
it is still allowing to insert "|"(pipe.)
0
 
LVL 82

Expert Comment

by:hielo
ID: 22828914
I know. You said:
>> it should not allow any special characters other than pipe.(|)

So, what is it you want?
0
 

Author Comment

by:amukta
ID: 22828915
what is test(o.value)?
0
 

Author Comment

by:amukta
ID: 22828921
I need it ASAP.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:amukta
ID: 22828922
i NEED IT asap.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22828950
>>what is test(o.value)?
o.value is the value of the text box

>>I need it ASAP
And if you don't clarify what you want, you are just delaying the process. I gave you EXACTLY what you asked for. So, if you mistyped the question you need to clarify.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22828953
If you want ONLY digits then use:
if( /[^\d]/.test(o.value) )
0
 

Author Comment

by:amukta
ID: 22836136
Is test(o.value) a function?
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22836272
>>Is test(o.value) a function?
Not a function. It is a method. Given this:
if( /[^\d|]/.test(o.value) )

get rid of the "if" clause and you are left with:
/[^\d|]/.test(o.value)

So, you can clearly see that I am using a RegExp object. The if statement I wrote is equivalent to:

var t = new RegExp("[^\\d|]", "");
if( t.test( o.value) )

if you are NOT familiar with reular expressions I suggest you refer to:
http://www.webreference.com/js/column5/index.html

If you are already familiar with regular expressions, then skip to:
http://www.webreference.com/js/column5/methods.html

so you become familiar with the supported methods.

On another note, still not clear what the issue is. You said you wanted to allow pipes, which it does. But then you said you don't, in which case just remove the pipe symbol from my original regex and it will allow only digits
0
 

Author Comment

by:amukta
ID: 24716716
Thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now