user-input

Allow only selected charcters based on regex in an EditText

感情迁移 提交于 2019-11-28 10:31:07
I want to allow users only to type certain characters based on the a regex in my android applications. How do I achieve it? Ragunath Jawahar Used a TextWatcher as @Matt Ball suggested. @Override public void afterTextChanged(Editable s) { String text = s.toString(); int length = text.length(); if(length > 0 && !Pattern.matches(PATTERN, text)) { s.delete(length - 1, length); } } Edit Although the TextWatcher works, it would be cleaner to use an InputFilter . Check this example . Try this: If the character to type matches /[a-zA-Z0-9{insert valid characters here}]/ then allow it, otherwise don't.

HTML input that takes only numbers and the + symbol

元气小坏坏 提交于 2019-11-28 09:55:05
I am trying to build a custom text input for phone numbers that accepts only numbers and the plus (+) symbol; all other characters need to be discarded and not shown on the field. I am trying to do this using an event handler (onkeydown/onkeypress) and discarding inputs corresponding to other keys. However, I can't figure out a cross-browser way to do it. Here are the approaches that I have tried and don't work: Using the onkeypress event and looking at event.key to figure out which key was pressed: doesn't work on Chrome (see http://caniuse.com/keyboardevent-key ). Is there any cross-browser

Android: custom view onClickEvent with X & Y locations

半腔热情 提交于 2019-11-28 09:34:38
问题 I've got a custom view and I want to get the X and Y coordinates of a user click. I've found that I can only get the coordinates from the onTouchEvent and an onClickEvent won't fire if I have an onTouchEvent. Unfortunately the onTouchEventfires when the user drags the screen as well as clicking. I've tried to differentiate between the two, but I still get the code firing when I'm dragging: public boolean onTouchEvent(MotionEvent event) { int action = event.getAction(); if (action ==

Problem with user input in my batch file

◇◆丶佛笑我妖孽 提交于 2019-11-28 09:20:26
问题 here is the portion of code giving me trouble: IF EXIST TH_BUILD_* ( ECHO A current build of Test Harness exists. set /p delBuild=Delete preexisting build [y/n]?: if "%delBuild%"=="y" (GOTO deleteandcontinue) else ( EXIT) ) For some reason, no matter the input, the batch file exits. Why is this happening (deleteandcontinue is never reached)? Thanks! 回答1: Try using delayed expansion when testing delBuild : setlocal enableextensions enabledelayedexpansion IF EXIST TH_BUILD_* ( ECHO A current

LibGdx, How to handle touch event?

陌路散爱 提交于 2019-11-28 08:55:32
问题 I am LibGdx Newbie, and trying to make my iceCream image touchable. I like to know how to set the input-process(by touch on screen). Do I need to make another class? When I try to implements the input-process to my Prac1 class, JAVA doesn't allow me to implements without changing the class abstract. To be specific, I like to make it whenever the user touch the image ,it counts the number of touch. Here is my code and Thank you for help. import com.badlogic.gdx.ApplicationAdapter; import com

Using isdigit for floats?

我怕爱的太早我们不能终老 提交于 2019-11-28 07:21:58
a = raw_input('How much is 1 share in that company? ') while not a.isdigit(): print("You need to write a number!\n") a = raw_input('How much is 1 share in that company? ') This only works if the user enters an integer , but I want it to work even if they enter a float , but not when they enter a string . So the user should be able to enter both 9 and 9.2 , but not abc . How should I do it? Use regular expressions. import re p = re.compile('\d+(\.\d+)?') a = raw_input('How much is 1 share in that company? ') while p.match(a) == None: print "You need to write a number!\n" a = raw_input('How much

How to export user inputs (from python) to excel worksheet?

不羁的心 提交于 2019-11-28 06:50:04
问题 I am trying to develop a user form in python 2.7.3. Please note that I am a python beginner. How to export user inputs (from python) to excel worksheet? Thanks 回答1: For writing your form, you may want to use Tk - it's built into Python ( import Tkinter ). For exporting to Excel, there are several options: write your data to a .csv file ( import csv ) then load it with Excel use a module to write to an .xls file use .COM automation to "remote-control" Excel Edit: ok, here's a more specific

How to stop user entering char as int input in C

时光毁灭记忆、已成空白 提交于 2019-11-28 06:33:11
问题 Heres a part of my code: printf("\nEnter amount of adult tickets:"); scanf("%d", &TktAdult); while (TktAdult<0){ printf("\nPlease enter a positive number!"); printf("\nEnter amount of adult tickets:"); scanf("%d", &TktAdult); } Right now it can only stop user from entering a negative value, but how do I add to it so it also stops user from entering a char?? 回答1: The following code rejects user input that are: non-numeric as handled by // 1; negative numbers as handled by // 2; positive

Check if an Edit Text that only accepts number is not empty and the number is equal or less than 100

早过忘川 提交于 2019-11-28 06:24:41
问题 I'm building an application for receiving grades and I want to make sure that the Edit Texts are not empty and the values are less or equal to 100 I wrote this line but it crashes the application if(Integer.parseInt(editText.gettext().toString()) > 100 || editText.getText().toString().trim().length() == 0) { //Error message for example } and this is the logCat 09-04 18:21:06.331 8649-8649/com.example.nima.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.nima

Fix a character to text input box using javascript/jquery

血红的双手。 提交于 2019-11-28 05:58:24
I am looking for a way to 'fix' a dollar symbol $ to a text input box eg <input type="text" value="$" /> but make it not possible for the default value to be removed, so that whatever the user inputs, there is always a $ symbol 'prepending' input. Cheers There is the possibility of a background-image but it's difficult to maintain, and doesn't react to font size changes, which makes it the less optimal choice IMO. A better way in my opionion would be: Put a <span>$</span> next to the input (before it, actually). give it position: relative; left: 20px . The $ sign then moves into the input