I want to create regex that can be used with jQuery that does below
No spaces
No special characters
Cannot start with number
I found most solutions for each point online, but I do not understand how to combine all 3. I will use this to alter a HTML form input when the form is submit.
Example someone writes '123 John' then it would change the input to just 'John' before submit. Or '123 John Is Me' becomes 'JohnIsMe' etc.
Why combine them?
Let's assume a user types in something invalid. Would it be better to say it's invalid, or would it be better to specifically say "cannot start with a number"?
Test each restriction separately, and return a helpful error message to the user based on what, specifically, is wrong with their input.
(Also, don't just change what the user types. That's confusing and bad experience as well. Have the user correct it, by telling them what's wrong.)
Related
I'm looking for a way to implement an autocomplete function of some sorts in TinyMCE that does not require a trigger character or shows a list of matches, but in stead suggests the continuation of a sentence like gmail does when you write an email.
(the rest of the sentence is suggested by the application)
In stead of the trigger character, the string to match will have to be for example the last few words typed, or the current sentence so far.
I have the backend to provide the actual suggestion based on a partial sentence but I can not find a way to implement this client side anywhere in the documentation. The only post on stackoverflow that looked relevant did not have the answer.
It does not work to simply not provide any trigger character, and it is also not possible to use a space bar / whitespace as the trigger character. Even if you could, it still needs to query the document for the querystring to send to my backend, not just the characters followed by a trigger character.
Should I not be using the autocomplete functionality for this? Is there a better way? How do I go about doing this?
https://fiddle.tiny.cloud/u7haab/12
I'm wanting to write a a block style input text box. I realized I might not be describing it correctly and if someone could give me the proper name, I would appreciate it. Basically I want the functionality of how GMail uses their email address client:
I don't need the autocorrect functionality, just the part where a user presses the enter key and it places it in a single entity/block and you can continue to type.
I'm sure there are libraries out there but I've had trouble finding them since I don't know what the technical name for them are. Any examples would be appreciated!
I am building a web app. I believe it will be easiest if I try to explain what I want the user experience to look like before I ask my question.
I want my user to go on my site and begin to type in a text field. When each character is inputted, I want to run a conditional statement on that character to decided if it should be added to the text field. If the character inputted is not one I want, the character isn't added.
I have validations in my model to do this after the text is submited, but I want it to be real time. I'm guessing this relates to JavaScript and I am not comfortable enough in coding it to know what to search for/research. Can you assist me in where to look (Tutorials, Concepts, etc)?
Thank you for taking the time to read this.
You can do this with the preventDefault method on the event object passed to the keydown event. This basically tells the browser to not preform its default action (which on a text field would be appending the letter to the field).
Here is an implementation using jQuery for brevity, but you can implement the same functionality in pure javascript as well:
$('input').on('keydown', function(event) {
// event.which is the character code
if ( /* some condition */ ) event.preventDefault();
});
And here is a fiddle with an example where you cannot type the letter A: http://jsfiddle.net/354XJ/
It's not precisely your situation but a very good starting point would be this question and its answers: How to allow only numeric (0-9) in HTML inputbox using jQuery?
You are basically looking for javascript that will intercept the keypress and only allow it if it is an allowed key, the question above implements this for numeric keys - start with that and expand it as per your needs.
I have an input that will have input between 3-5 alphanumeric characters.
I want to validate that the user input between 3-5 characters:
/^[A-Za-z0-9]{3,5}$/
But, I want to ignore any alpha characters on form submission, not strip them.
So an input value of "RS032" stays that way in the input on form submission, but the form only actually returns "032"
The question is a little shy of details, but I'm guessing you want to validate everything in the field except letters. So, if the input is abc1d2e3fgh and your requirement is 3 digits, you want that to pass.
For a very basic requirement like this, you can intersperse optional [A-Za-z]*? sets between the other required characters. So, for the 3-numbers requirement, you could use
[A-Za-z]*?\d[A-Za-z]*?\d[A-Za-z]*?\d[A-Za-z]*?
This requires 3 digits (\d), and allows any number of letters before, between, or after those digits.
If you need to use match/capture groups, instead of just verifying match/no-match this won't work.
Unless you have a very basic requirement, there is no way that I know of to achieve this with a single RegEx. You'll likely need to assign the string to another variable, strip the letters, and then validate. By assigning to another variable, you can leave the input in place.
Update in response to question edit:
It sounds like you do want to strip the letters, only you want to do it in the backend. I think that is exactly what you should do, instead of conflating that with validation.
If you really want to do the work client-side, you could use an additional, hidden field, that you update via Javascript when the "source" text changes. On the server you can ignore the "source" field and instead use the "stripped" one.
i need some decision help today :-)
interface A) an input field where the user can type his search parameters.
interface B) next step he will come to some mask, where he can refine his search.
if he enters some defined words (there are about 10) in A the corresponding checkboxes in B should be be checked. Next to these Words he can enter other stuff, which will be found after step B is submitted
the interface A should help the user via auto-complete function for those few words
if the user does not care about the suggested words and still spells my keywords wrong, the system should find them although.
sounds after phonetic search for me, but is it necessary to implement a full featured algorithm for 10 Words, that could be found?
is there an admitted easier/faster/lightweight way to do this?
thanks in advice
I think that you could use double metaphone. It is used by some spelling checkers.
Might be exactly what you are looking for.
You could store a list of possible/common misspelling for each - much simpler.
For simple misspelling (letter switching, etc.) - a simple distance measuring heuristic would also be a good idea.