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
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

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

Author Comment

by:amukta
ID: 22828921
I need it ASAP.
0
 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

696 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