Validating PDF Form Fields for number characters only - javascript

Developing a PDF form that requires field validation. I am using Bluebeam however from what I see so far it works exactly the same as any other PDF form creator.
So I am trying to validate the field for number characters only and accept the value if it is number characters (must also accept text starting with single and multiple 0's). The following was having a guess of what it might have to use.
var fld = this.getfield(“Text1”)’
If IsNumeric(“Text1”) == true;
event.value = fld.value
else
alert(“Error message”)

Try this hope this helps:
var fld = this.getfield(“Text1”).value;
if(fld.match(/^\d+$/)){
event.value = fld.value;}
else{
alert(“Error message”);}

Related

How to validate and handle input when email and phone has same textbox

I am looking for a way to deal with following use case.
A user can enter either phone number or email address in order to get password reset token in an ionic app.I cannot change the UI to have two field as BAs won't accept it.Following screenshot shows the MOCK UI:
Problem: 1. Since there is just one input field how to validate if user entered either phone number or email address?Is there any definitive regex for it?
Since there is just one input but two different type of data, how to decide on model?Should I have just one model(field) of type string and use the same for both after UI validation or should I use two different field as model for this scenario?
ANother challenge is enabling the submit button when a valid email address is entered or phone number is entered.Phone number can be of international type.
Try like this
var input = "your angular model input";
var emailReg = /^([w-.]+#([w-]+.)+[w-]{2,4})?$/;
if(emailReg.test(input))
{
$emailModel = input;
} else {
var mobileRegex = /[0-9 -()+]+$/;
if((input.length > 6) && (intRegex.test(input)))
{
$mobileModel = input;
}
}

jjquery code snippet to validate telephone number input

So I'm using Knack and a Jquery code snippet to extend the Knack featureset. I want to validate a telephone number entered into a form on Knack. Knack provide this code example, but it doesn't do quite what I want it to do.
// Your app's ViewID and FieldID will need updated.
$(document).on('knack-view-render.view_97', function(event, view, data) {
$("#view_97 .kn-submit input[type=submit]").on("click", function() {
// if this value in my form doesn't equal "SpecificValue" then prevent the form from submitting
if ($("#view_2-field_29").val() != "SpecificValue") {
alert ("These are not the droids you are looking for.");
return false;
}
})
})
Basically I would like the validation to either strip out (preferred) or not accept (next best!) spaces and insist on being given a mobile number which is either " " (a space) or a number in the format 00000000000. 11 digits.
Thank you for any help!
To strip out any non-digits in the number and take the first 11:
$("#view_2-field_29").val().replace(/\D/g,"").slice(0,11)

javascript validation not working for only alphabetic values

I have used a javascript validation function to validate it. I've used it to see whether the text entered to the html textbox is alphabetic(No numeric characters allowed). The function is called during onkeyup and onblur. The only problem is even when numeric values or special characters are typed in the validation doesn't work. If I leave the field blank then it works(Displays that the field is left blank). Here's my javascript code:
function isAlphabetic(x,y){
var exp = /^[a-zA-Z]+$/;
var a = document.getElementById(y).value;
if(a=="" || a== null){
document.getElementById(x).innerHTML = "You cannot leave this feild empty";
return;
}
else if(a!="" && a!= null){
if(y.match(exp)){
document.getElementById(x).innerHTML = "";
return;
}
else{
document.getElementById(x).innerHTML = "Only enter alphabetic characters allowed";
return;
}
}
else{
return;
}
If you use y as an id of element, I suppose you shouldn't check it with your regexp. Instead you should check a:
if(a.match(exp)) {
You don't need JavaScript anymore for any of this. Use the pattern attribute on the input field and the browser won't let the user enter anything that doesn't match, and use required to prevent submitting the form with an empty value.
Also, do you really want only ASCII letters? (are spaces allowed? how about non-ASCII letters such as "é"?)

check input fields with javascript

i am using the following code to check if user doesnt input special characters in name
var regex = /^[a-zA-Z ]{2,50}$/;//check for only letters
var ctrl = document.getElementById('input1');//given name field
if(!regex.test(ctrl.value))
{
alert('Ensure field Name contains only letters[A-Z]');
return;
}
can someone please help to change regex so client can also enter JUST one (')(IF NEEDED) e.g O'Daniel.
also for phone no field limit user with only one +
Thanks in advance.
You don't have to cram all the logic into a single regexp. To check for apostrophes, simply do a separate check:
var apostrophes = ctrl.value.match(/'/g);
return !apostrophes || apostrophes.length < = 1;
Use the same logic to check for no more than one + in the phone number.

Enter digits into a masked input field in a free form format using jQuery

I would like to build a form input using the mask plug-in that will change the characteristic of the entry for time to permit the user to enter digits in a free form format and the system will convert the entered digits into proper time display using jQuery.
Example: the user to enter “135” and the system to convert this to “01:35”
The code for the mask is:
$("input.time").mask("99:99");
So far I have the code below:
$(document).ready(function() {
$('#awareness-hour').blur(function() {
if(!$('#awareness-hour').val().match(/([0-1][0-9]|2[0-3]):[0-5][0-9]/)){
alert('invalid');
}else{
return true;
};
});
});
This will correct the scenario you mentioned and update the input only if it's a valid time according to your second regular expression. Hopefully, you get the idea and this works:
$("input.time").blur(function() {
var userInput = $(this).val().replace(/^([0-9])([0-9]):([0-9])_$/, "0$1:$2$3");
if(!userInput.match(/([0-1][0-9]|2[0-3]):[0-5][0-9]/)){
alert('invalid');
}else{
$(this).val(userInput);
return true;
};
}).mask("99:99");

Categories

Resources