Connecting Tech Pros Worldwide Forums | Help | Site Map

Allow Only PRE Defined Characters . .

Member
 
Join Date: Nov 2006
Posts: 64
#1: Dec 6 '07
Hi All,

I am trying to include only the following characters in my textbox. Will anyone please provide me some source code or idea . .

Textbox must accept only 0-9, space ,hypens(-) and characters(a,b and Z)

Regards,
Nedu. M
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,132
#2: Dec 6 '07

re: Allow Only PRE Defined Characters . .


hi ...

you may use a regEx for that purpose:

Expand|Select|Wrap|Line Numbers
  1. var re = /^[0-9abZ-]+$/;
  2. var value = '12-aZ';
  3.  
  4. var ret = re.test(value);
kind regards
Member
 
Join Date: Dec 2007
Posts: 37
#3: Dec 7 '07

re: Allow Only PRE Defined Characters . .


Quote:

Originally Posted by gits

hi ...

you may use a regEx for that purpose:

Expand|Select|Wrap|Line Numbers
  1. var re = /^[0-9abZ-]+$/;
  2. var value = '12-aZ';
  3.  
  4. var ret = re.test(value);
kind regards

Don't mean to haggle you gits and I don't mean to intrude, but nudu I think wanted spaces as well.

Expand|Select|Wrap|Line Numbers
  1.      var re = /^[0-9abZ\s-]+$/
  2.  
should add the white space characters. If you don't want tabs and such, then try the following.

Expand|Select|Wrap|Line Numbers
  1.      var re = /^[0-9abZ\x20-]+$/
  2.  
\x20 being the space character in hexidecimal.

Please correct me if I'm wrong.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,132
#4: Dec 8 '07

re: Allow Only PRE Defined Characters . .


yep ... i missed the spaces ... thanks for pointing that out ...
Member
 
Join Date: Nov 2006
Posts: 64
#5: Dec 11 '07

re: Allow Only PRE Defined Characters . .


Thanks a lot for all . . I got t . . .
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,132
#6: Dec 11 '07

re: Allow Only PRE Defined Characters . .


glad to hear that ;) ... post back to the forum anytime you have more questions ...

kind regards
Reply