Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,
i want to write that a javascript function that allows only numbers,* and ?.
Posted
Comments
Maciej Los 16-May-13 2:52am    
Have you tried something?

The regex is simple:
^[\d\*\?\.]*$
 
Share this answer
 
Comments
Mohibur Rashid 16-May-13 3:10am    
i need to learn regex :)
OriginalGriff 16-May-13 3:23am    
Get a copy of Expresso

http://www.ultrapico.com/Expresso.htm

Iit's free, and it examines and generates Regular expressions.
Mohibur Rashid 16-May-13 3:29am    
thanks, sure will do
Arjun Menon U.K 20-May-13 1:58am    
Hi, i have a doubt. i want to check a textbox value with regex that allow only a-z,A-Z,0-9.. i came across a regex ^[a-zA-Z0-9]+$ and ^[a-zA-Z0-9]*$
I would like to know what the +$ and *$ means. The ^ denotes starting of the string being checked rt? . Please correct if i am wrong
OriginalGriff 20-May-13 2:23am    
+ means "one or more"
* means "zero or more"
^ means "start of string"
$ means "end of string"

Get a copy of Expresso - it explains this and helps a lot - the link is just above!
There is several key event that can be handled for user input controlling.

for simplification I will only talk about onkeypress

to process a user input you must have to return true or false.

as example

HTML
<input type=text onkeypress='return false;'> <!-- this will discard whatever the user types-->
<input type=text onkeypress='return false;'> <!-- this will allow whatever the user types-->


try this on browser.

say you want to allow only 0 and 1. the simple example would be

HTML
<script>
function test(e){
 var e=window.event || e
 //alert(e.charCode);
 return e.charCode==48 || e.charCode==49 ? true:false;
}
</script>

<input type=text onkeypress='return test(event);'> <!--only let you print 0 or 1 -->


hope it will guide you a little
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900