Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Mon Nov 23, 2009 3:11 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ]  Bookmark and Share
Author Message
 Post subject: JavaScript Validation of only "|" (pipe) in the sp
PostPosted: Tue Nov 11, 2008 3:14 pm 
Offline

Joined: Tue Nov 04, 2008 1:08 pm
Posts: 21
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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2008 6:51 pm 
Offline

Joined: Sat Sep 06, 2008 5:06 pm
Posts: 40
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 ;)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2008 3:54 am 
Offline
500+ Club
User avatar

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

_________________
~ Get me some work, I do freelancing ~


Top
 Profile  
 
 Post subject: Re:JavaScript Validation of only "|" (pipe) in the
PostPosted: Wed Nov 12, 2008 5:22 am 
Offline

Joined: Tue Nov 04, 2008 1:08 pm
Posts: 21
rangana wrote:
A basic example:
Code:
<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:
<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:
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)
      }



Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2008 8:06 am 
Offline
500+ Club
User avatar

Joined: Wed Feb 27, 2008 6:14 am
Posts: 929
Location: Cebu City Philippines
What's the name of your textarea? Reading the code, you could have simplified it with this:
Code:
<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)">

_________________
~ Get me some work, I do freelancing ~


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2008 12:46 pm 
Offline

Joined: Tue Nov 04, 2008 1:08 pm
Posts: 21
rangana wrote:
What's the name of your textarea? Reading the code, you could have simplified it with this:
Code:
<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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2008 1:01 pm 
Offline
500+ Club
User avatar

Joined: Wed Feb 27, 2008 6:14 am
Posts: 929
Location: Cebu City Philippines
No problem, glad to be of service ;)

_________________
~ Get me some work, I do freelancing ~


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley