I want to utilize inputmask plugin for special character & maxlength validation for text box. It supports either one. Is there a way to implement this?
var pattern = /^[\w\s\/\&\'\-]*$/i;
$("#example1").inputmask("99-9999999");
$("#example2").inputmask(pattern);
Related
I have textBox which accept alphabeti want to validate the textBox contain proper Drive Path or not using javascript
ex:Suppose Textbox contain 'D:\' then it's valid or else it's invalid...I need to check textbox contain ':\' or not after alphabet
plz help me
try to use javascript method "replace" http://www.w3schools.com/jsref/jsref_replace.asp to remove unwanted contents.
You can use following regex
/^(\\(\\[^\s\\]+)+|([A-Za-z]:(\\)?|[A-z]:(\\[^\s\\]+)+))(\\)?$/
I am new to javascript and I couldn't find the exact code for my need.
I want a text field with maxlength="5" which should look like ex:AE456, LM975. i.e., the first two letters ahould be alphabets and next three letters should be numbers.
the text area should accept input according to this pattern only. I don't want any alert. Simply it has to accept whatever typed only in this pattern.
Javascript is preferrable. Any help is greatly appreciable.
Thanks in advance.
HTML5 supports pattern where a field can accept values as per the supplied regex. You can find related post here.
Regex Patterns for HTML5 Text Field
But if you want to support older browser, then you have to attach events like "keypress" to the input field, and handle the event to validate the input
If you have this HTML:
<input type="text" id="text1" />
Then you could use this Javascript:
function validateInput() {
var val = document.getElementById("text1").value;
return /[A-Z]{2}\d{3}/i.test(val);
}
and call it like:
if (validateInput()) {
// Matches pattern: #####
}
DEMO: http://jsfiddle.net/GgQsz/
This allows uppercase and lowercase alpha characters at the beginning. If you want to only allow uppercase, remove the i flag for the Regex.
What you need is a regular expression. Check out regular expression here. This should give you an idea as to how to check for your condition.
http://www.w3schools.com/jsref/jsref_obj_regexp.asp
I'm using jQuery's validation plugin to validate a form.
I have a field which should only contain letters or numbers. I have tried the following regex but it's still allowing characters such as ' ; :
[a-zA-Z 0-9]$
What am I doing wrong?
Thanks in advance
Try this:
^[a-zA-Z 0-9]*$
If this is a required field, then change asterisk to plus:-
^[a-zA-Z 0-9]+$
Try this expression::
^[a-zA-Z 0-9]+$
I am using a textbox on my page which is used to enter year in yyyy-yyyy format.
Can you tell how can i validate textbox in this format through javascript??
Thanks in advance...
You can match it with a regular expression:
var pattern = /\d{4}-\d{4}/;
If you are not using any javascript library (like jQuery, etc), Javascript Regular Expressions could be used for validating the input.
Hey guys,
unusual question: I have a input field #birthday that should accept european date format like this. dd.MM.yyyy
I wonder if it is possible to auto apply dots when typed into this field.
Imagine the inputfield is focused and empty. I start typing to numbers and the field autogenerates a dot, again two numbers and a dot is generated.
My aim is to type only numbers without needing to add the dots.
any idea how i could achieve that with jquery or javascript in general?
$('#birhtday').keypress(function() {
// ?
})
Why not use existing jQuery plugins?
Masked input
meioMask - I find it nicer because it doesn't use those underscores (but it seems to have some bugs when TABing through filled form)