Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
User avatar
By ebryant
#826979
I'm trying to limit (control) users who can utilize a submit button by inserting a code number:

form = getFormById("9266651675dcc61127194f5057208399");
form.setOnSubmit(function(){
if ($("#Num").getValue().search(/AD-2019[74-9]0[A-Z]/i) == -1)) {
alert("STOP...Incorrect value.");
return false; //stop submit
}
});

I would like to utilize a list of unique acceptable numbers like (AD-201970A, AD-201956B, etc...).
User avatar
By RicardoMG
#827929
Hello!

So you can control the submit button by inserting a code number, I did the following example.
I created a case where I have only one task, likewise i created 3 variables: name: string, email: string and code: string.
In the form I have the following code using JavaScript:
Code: Select all
$("#submit").find("button").click(function(){
    var name = $("#code").getValue() 
    var re = new RegExp("^[AD]{2}-[2019]{4}[0-9]{2}[A-Z]$");
    if (re.test(name)) {
       return true; //continue submit
    } else {
       alert("your code is wrong, you can not send the form until you enter the correct code");
       return false; //stop submit
    }
});
so in this JavaScript code valid using regular expressions that the value in the code variable has the structure as you want (AD-201970A, AD-201956B, etc.), for this I did a video of how it works and i attached it to the comment.
I hope this little development helps you.

Best regards, Ricardo.
Attachments
(21 MiB) Downloaded 235 times
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]