I am creating a ASP.NET web app and I need to mask the input string in a textbox. The string needs to be masked like:
DR117-17
So, two characters(DR), followed by 3 digits, followed by a '-' and followed by the fiscal year(yy).
The user has to actually input only the 3 digits (ex:'117').
The perfect solution would be that the characters 'DR' are automatically inserted on click, then wait for three digits to be input and then automatically add the '-17'.
Using the jQuery mask plugin is pretty straightforward:
$("#date").mask("DR999-17");
Working fiddle: http://jsfiddle.net/55003z11/
Related
I am trying to generate a regex which would match the following sequence-
+91123456789,+41123456789,+21123456789.... and so on, there is no limit of phone numbers.
Basically the usage is to validate the phone numbers which users may add, phone number can be multiple and need to be separated by commas, I am already removing the empty spaces which users may add, so no worry for that.
I am not good with regex and have created the following regex but it doesn't matches the preceding phone numbers, means the whole string of phone numbers do not match-
^\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9},\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}$
I need to validate the user input using javascript or jquery.
Valid Phone number should be having country code like +91 or +21 etc country code can be of one or two digits, then the number of digits need to be 7 to 9.
I anyone could help, it would be highly appreciable, I have spent lot of time on this one.
To validate the whole string handling mulitple values sepparated by comma just add an group with * multiplier:
^\+\d{8,11}(,\+\d{8,11})*$
If I understand the requirements correctly, the following regex should work
\+\d{9,11}
However, you can separate the country code out, for if you need to allow for (+44)xxxxxxxxx
\+\d{2}\d{7,9}
if the requirement is to allow for 1 country code as well, adjust the regex to the following
\+\d{1,2}\d{7,10} //I think to 10, not sure on their numbers
You can update the ranges as you see fit :)
Demo: https://regex101.com/r/rJ4wM7/1
I'm not an advanced programmer, but I've learned some basic stuff in order to customize some PDF documents that are used in a third party web app. It basically takes an XML stream from a mainframe and populates fields in the form. The mainframe is currently sending over data for a zip code +4 field incorrectly. It's adding a second "+4" string. For example, if the string should be 12345-6789, it's coming over as 12345-6789-6789.
What I need to do is strip the last 5 characters from that data and place it in a field. Below is what I have, and it's not working
var badcsz = this.getField("CSZ_FROM_MAINFRAME");//XMLDATA FROM MAINFRAME "CSZ_FROM_MAINFRAME"
var csz = this.getField("CORRECT_CSZ");//CORRECT_CSZ IS THE FIELD IN THE PDF
csz.value = badcsz.slice(0,-5);//
csz.value = badcsz.slice(0, badcsz.length-5);
With a regex can write a safer "remove last 5 chars" routine by using
csz.value = badcsz.replace(/(-\d{4})-\d{4}$/,'$1');
This has the benefit of not just always removing the last 5 chars, but will only remove the last 5 chars if they match the pattern: '-' followed by 4 digits (twice).
I have an input field named "VERSION" in a form where I have to write the version of the document.
e.g.
Version : 10.1.2.3
How to validation for this input field in javascript?
Can you use a regular expression?
(\d+\.)+.\d+
Meaning: one or more digits, followed by a point, repeated as many times as you want, followed by a point and one or more digits.
If you have to have 4, you can make it more specific:
(\d+\.){3}.\d+
If it has to be 2 digits, one one one, try:
\d\d\.\d\.\d\.\d
As you see, you need to be more clear about "what is a valid version, and what is not" in order to obtain a more specific answer :]
You mean you'd validate if there is a version input in the correct format?
(use an ID for the input field)
if(document.getElementByID('VERSION').value.match(/^\d+\.\d+\.\d+\.\d+$/)) {}
This should match all versions in the format {number}.{number}.{number}.{number}
Maybe you have to trim the string before you do that
I have 3 TextBoxes on the page. How do I setup one validator (and what's kind of validator?) to validate each of TextBoxes on client side?
First textBox must contains only 1-3 number of digits, second - infinite number of digits, third - 0-5 number of digits
It would be better to use different validators for different text boxes.
Use 3 validators for each with display message as * sign.
Then use Validation Summary control to print a single message for all of them, as you want a single message to be displayed for all. Refer this link: MSDN Validation Summary
Check this too: Validation Summary to work with client-side validations
Your expressions would be along the lines of:
[0-9]{1,3}
[0-9]+
[0-9]{0,5}
Updated following further info:
You could combine the values from each text box into a comma separated value and then validate that using [0-9]{0,3},[0-9]+,[0-9]{1,5} expression.
Either use javascript to copy the value into a hidden textbox field with it's own regex validator using above expression, or just perform the validation manually.
e.g. Using jquery
$('#hiddenCombinedField').val($('#field1').val()+','+$('#field2').val()+','+$('#field3').val());
Run this just before you call validate on the form.
See also http://speckyboy.com/2009/12/17/10-useful-jquery-form-validation-techniques-and-tutorials-2/ for some useful reference material.
You could use a CustomValidator but i would prefer using three distinct validators, one for every TextBox.
It's possible to leave the ControlToValidate-property of the CustomValidator empty. On this way you can validate multiple controls at the same time.
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)