473,411 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Require only numbers and '-' in the value for a text input

I hav a text box n how do i validate it for entering only numbers and "-" and where do i include my javascript in JSF....
Sep 25 '07 #1
7 3010
dmjpro
2,476 2GB
I hav a text box n how do i validate it for entering only numbers and "-" and where do i include my javascript in JSF....
Welcome to TSDN.

You can simply use <script>some JavaScript code</script> as you use in other Markup Language.

Kind regards,
Dmjpro.
Sep 25 '07 #2
pbmods
5,821 Expert 4TB
Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).
Sep 28 '07 #3
acoder
16,027 Expert Mod 8TB
I hav a text box n how do i validate it for entering only numbers and "-"
Use regular expressions. Try, e.g.
Expand|Select|Wrap|Line Numbers
  1. /^[-0-9]+$/
Sep 28 '07 #4
acoder
16,027 Expert Mod 8TB
I hav a text box n how do i validate it for entering only numbers and "-" and where do i include my javascript in JSF....
See this article .
May 18 '08 #5
malav123
217 100+
Hi,
use following function that will allow only digits.....
Expand|Select|Wrap|Line Numbers
  1. function onlyDigit(e)
  2. {    
  3.     var unicode=e.charCode? e.charCode : e.keyCode            
  4.     if (unicode!=8 && unicode!=9 && unicode!=46 && unicode!=39 && unicode!=37)
  5.     { 
  6.         if((unicode<48||unicode>57) && (unicode<96||unicode>105))
  7.         return false
  8.     }                                
  9. }
  10.  
May 20 '08 #6
acoder
16,027 Expert Mod 8TB
Instead of all that code, you'll find a simple regular expression to be better.
May 20 '08 #7
malav123
217 100+
Instead of all that code, you'll find a simple regular expression to be better.

Yes it's true... regular expression is better way to accomplish task...
May 21 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Eddie | last post by:
I need to validate a text input field. I just want to say if user enters 93101 or 93102 or 93103 or 93105 or 93106 or 93107 or 93108 or 93109 or 93110 or 93111 or 93116 or 93117 or 93118 or...
5
by: JeffFinnan | last post by:
Is there a way to have a text input field equal some variable value so that it changes if that variable changes? It does not have to by dynamic. <INPUT TYPE="TEXT" NAME="hW" size="4" value=some...
8
by: BiNZGi | last post by:
Hi I have reduced the problem to this code: <form> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td><input type="text" style="width: 100%;" value="Lorem ipsum dolor...
1
by: ron | last post by:
You know how some web pages require text input, well I'm doing this by running a VBA macro out of Excel. The macro opens IE to the desired url and the following lines of code insert the required...
5
by: Art | last post by:
Hi, I'm using a form text input to display a JavaScript clock. It has no other purpose than that, just show the date and time. What I would like to do now is prevent anything else happening when...
4
by: ms | last post by:
I have come across a problem where if a user enters the same text into a text input after the value has been programmatically changed, the onChange event does not fire for the second change. The...
5
by: PJ | last post by:
I've been using this function to limit a text input to numbers only with success on an old site. function checkForInt(evt) { var charCode = ( evt.which ) ? evt.which : event.keyCode; return (...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
11
by: Mike Harrison | last post by:
Hi, I have some simple HTML like this: <div id="container" style="width:100%;"> <input type="text" <input type="button" style="float:right;" value="Click here..."> </div> I want the button...
0
by: pazazuzu | last post by:
Hi everyone, I currently have an assignment which I am almost done with but am having problems trying to figure out how to integrate a string function search. I have a text box called...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.