It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Partner Sites
Board index Programming JavaScript Forum

JavaScript Validation of only "|" (pipe) in the sp

JavaScript Validation of only "|" (pipe) in the sp

Postby neha_kulkarni777 on Tue Nov 11, 2008 3:14 pm

In my textbox I should be able to allow all characters, numbers and special characters except "|" (Pipe) .
The validation should be done using javascript.
I am having the Javascript code for validating all the special characters
But i need to validate only "|"(Pipe) in all special characters

It is very urgent
I need it ASAP.
neha_kulkarni777
 
Posts: 21
Joined: Tue Nov 04, 2008 1:08 pm

Postby Dantenas on Tue Nov 11, 2008 6:51 pm

If you have the code, then just delete all the special symbols except | from it. Hope yoy get what I mean, if not, give us your script ;)
Dantenas
 
Posts: 40
Joined: Sat Sep 06, 2008 5:06 pm

Postby rangana on Wed Nov 12, 2008 3:54 am

A basic example:
Code: Select all
<input type="text" value="t|e|s|t" onblur="alert(this.value.indexOf('|')>-1?'Pipe should not exist.':'It\'s a valid input');">
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 6:14 am
Location: Cebu City Philippines

Re:JavaScript Validation of only "|" (pipe) in the

Postby neha_kulkarni777 on Wed Nov 12, 2008 5:22 am

rangana wrote:A basic example:
Code: Select all
<input type="text" value="t|e|s|t" onblur="alert(this.value.indexOf('|')>-1?'Pipe should not exist.':'It\'s a valid input');">


the above code is working very fine but
My requirement is , when i enter "|" (pipe) it must not show in the text grid . Please see my code and reply me ASAP .

The below code is my text area
Code: Select all
<textarea rows="4" cols="40" onKeyDown="textCounter(this.form.UNFCCC_Comments,this.form.remLen, 250)" onKeyUp="textCounter(this.form.UNFCCC_Comments,this.form.remLen, 250)"  >


The below code is JS
Code: Select all
function textCounter(field, countfield, maxlimit) {
      //var re = /^[a-zA-Z0-9\n\r\f]*$/; // checking for all the special characters.
      var re = "t|e|s|t" ;
      if (!re.test(field.value))
         {
         field.value = field.value.replace(('|'),"");
         //alert(this.value.indexOf('|')>-1?'Pipe should not exist.':'It\'s a valid input');
         }
      else if (field.value.length > maxlimit) // if too long...trim it!
         field.value = field.value.substring(0, maxlimit);
         
      else    // otherwise, update 'characters left' counter
         countfield.value = maxlimit - field.value.length;
      }

      function trim(str)
      {
         return str.replace(/^\s*|\s*$/g,"");
      }
      function startsWith(str1, str2)
      {
         return (str1.match("^"+str2)==str2);
      }
      function endsWith(str1, str2)
      {
         return (str1.match(str2+"$")==str2)
      }

neha_kulkarni777
 
Posts: 21
Joined: Tue Nov 04, 2008 1:08 pm

Postby rangana on Wed Nov 12, 2008 8:06 am

What's the name of your textarea? Reading the code, you could have simplified it with this:
Code: Select all
<script type="text/javascript">
var ray={
filter:function(el,limit)
   {
   val = el.value.replace(/\|/g,'') ; // Trim trailing white spaces
   el.value=val;
   }
}
</script>
<textarea rows="4" cols="40" onKeyDown="ray.filter(this,250)" onKeyUp="ray.filter(this,250)">
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 6:14 am
Location: Cebu City Philippines

Postby neha_kulkarni777 on Wed Nov 12, 2008 12:46 pm

rangana wrote:What's the name of your textarea? Reading the code, you could have simplified it with this:
Code: Select all
<script type="text/javascript">
var ray={
filter:function(el,limit)
   {
   val = el.value.replace(/\|/g,'') ; // Trim trailing white spaces
   el.value=val;
   }
}
</script>
<textarea rows="4" cols="40" onKeyDown="ray.filter(this,250)" onKeyUp="ray.filter(this,250)">


Thanks a lot rangana for replying my mail ,. Its is working
neha_kulkarni777
 
Posts: 21
Joined: Tue Nov 04, 2008 1:08 pm

Postby rangana on Wed Nov 12, 2008 1:01 pm

No problem, glad to be of service ;)
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 6:14 am
Location: Cebu City Philippines


Who is online

Users browsing this forum: No registered users and 4 guests