What is the REGEX for ALAA-123456 - html

I'm a newbie at php.
HTML form is capturing data and mailing it to user via php.
I am trying to make this field have a default value of "ALAA-" and then only permit 6 numbers after "ALAA-". I believe I need the REGex for this but I can't figure out the code. thank you!
<div class="form-group">
<label for="form_moms_alaa_registration">Doodle Mom's ALAA Number *11
digits</label>
<input id="form_moms_alaa_registration" type="text" pattern=""
default="ALAA-123456" tabindex="5" value="ALAA-"
name="inputmomsalaaregistration" class="form-control"
placeholder="ALAA-######" data-error="Doodle Moms ALAA registration
should have 6 numbers. It is a required field." required>
<div class="help-block with-errors"></div>
</div>

While sending your client-side HTML form PHP will get the values sent with the tag how the post method , but first I suggest using a JQuery script to validate the upload data see more information to get values in HTML attributes:
help about get attribute value
For the server side, PHP manipulates variables that you can treat this value using regex:
preg_match('/ALAA-[0-9]{6}/', $_POST['YOURFIELD'], $matches);

Here is the regex you need
pattern="ALAA-\d{6}"
You could also write it as:
pattern="ALAA-[0-9]{6}"
I don't think either is more correct than the other, but some people might have opinions about which is more readable.
\d means match any digit. [0-9] means match any character in the range of 0-9 so that is effectively the same thing as \d
The {6} means match exactly 6 repetitions of the preceding character

Related

Pre-validation of an input field in HTML

Is there any way to validate inputs in the form using HMTL?
For example:
<input type="text" class="input-text error"
aria-required="true" placeholder="Enter your name *"
aria-invalid="true" required />
If user adds a special character to input, an error message saying "Characters are not allowed" should be shown below the input box.
First of all, client-side form validation is the greatest feature coming with the HTML5. Client-side form validation helps you to ensure data submitted matches the requirements. To get more detail about it you can visit here.
Important Note
Client-side form validation is an initial check, You should not use data coming from the form on the server side without checking it. It just a feature for good user experience. Because client-side validation is too easy to manipulate, so users can still easily send data that you do not want to on your server.
Solution
In this question, the best solution is; using HTML attribute pattern. The pattern attribute defines a regular expression the form control's value should match. To get more detail about pattern attribute you can visit the this page.
Below regexp you need.
^[a-zA-Z0-9]{5,12}$
It works like that;
It should contains only alphanumeric.
Minumum 5 and maximum 10
character.
You can use below code to integrate it with input field.
<form action="">
<input type="text" name="name" required
pattern="[a-zA-Z0-9]{5,12}" title="No special character">
<input type="submit">
</form>
Usually, to check inputs from html tags, you can create a javascript function to check your needs which is called everytime the user type in your input with the "onkeyup()" function.
The "onkeyup" keyword will trigger the function everytime user type in your field
<input type="text" onkeyup="myFunctionToCheck()">
<script>
myFunctionToCheck(){
//Here check your needs
}
</script>

How to multiply a number that has been enter in the form of html and display with a number while using html

when we enter the number in the form of html it will automatically multiply by 20. how to show the the answer on next field while using html?
HTML is a markup language (used for structuring/organizing your data), not a programming language (used for calculations...etc). For calculations, you'll likely want to utilize JavaScript to retrieve the values from the HTML fields, do some calculations, then write the value to the next field. There are other options, but that's probably the best place to start.
Add an event listener.
<form>
<input type="text" id="t1" oninput="getElementById('t2').value = this.value * 20">
<input type="text" id="t2">
</form>

HTML form password requirements

I need to create a registration form in HTML which has a password input with the following constraints:
Is a mandatory field, should be validated. Minimum of 7 characters. Should have at least one special character and one number. Do not use java script, use HTML 5 features.
I have written the following code to for the above input:
<input type="text" name="password" pattern="(?=.*\d)(?=.*[\W_]).{7,}" required>
I need to submit this code as part of an assignment and I get the error:
Correct HTML Component with the name 'password' must be used with appropriate constraints
which means I am not using the correct attributs.
What changes should I make to the pattern attribute?
This code works perfectly with validation message
<p>Password: <input type="password" name="pw" pattern="(?=.*\d)(?=.*[\W_]).{7,}" title="Minimum of 7 characters. Should have at least one special character and one number."></p>
try it here :
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_pattern3
I think this will work.
Password:<input type="password" name="pw" pattern="^(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!#$%^&*-]).{7,}$" title="Minimum of 7 characters. Should have at least one special character and one number and one UpperCase Letter.">
Pattern attribute will also use a Regular Expression to validate your form-data.So for more results you can also search for Regular Expression

Why doesn't the pattern or required attribute work?

I am currently doing homework, and following the instructions the book gives me, but I can't get the required or pattern tags to work. I am creating a survey form, and trying to make an error come up when the user doesn't type in their name, receipt number, or email. Here is a portion of it.
<label for"receipt">Receipt number *</label>
<input name="receipt" id="receipt"
placeholder="re-nnnnnn"
required="required"
pattern="^re\-\d{6}$" />
A few things i see
the required attribute does not need a value, the existence of the attribute is what makes it required or not.
the - does not need to be escaped so use ^re-\d{6}$ for the pattern attribute
the issue with the notepad++ is that the language formatting/color-coding is not up-to-date with all the attributes.
<input name="receipt" id="receipt"
placeholder="re-nnnnnn"
required pattern="^re-\d{6}$" />
there is no need to write like that u can just write : required and it will work
and whats your pattern i don't catch that

HTML form values adding commas in Classic ASP

I have a classic ASP page that submits back to itself. Strangely, the values being returned from the selects have commas being added to the ends of them. Has anyone run into anything like this before? Any troubleshooting steps or tools recommended?
I'm expecting the values to be returned just as numbers - they are the IDs of the values displayed in the option.
I've checked for mystery commas in the page and can't locate any - nor in the data that I'm pulling through.
(note - these are single-selects, not multiple)
Sounds like you have duplicate form fields. Your values are concatenated together with commas, like this:
<input type="text" name="name1" value="value1">
<input type="text" name="name1" value="value2">
<input type="text" name="name2" value="value3">
Becomes
name1=value1,value2
name2=value3
If the second name1 has no value, it becomes
name1=value1,
name2=value3
Do you have multiple form elements on your page with the same name?
In classic ASP, multiple form values with the same name are joined into a comma-separated string in the Request.Form / Request.QueryString collections - so if there's a hidden field or textbox with name="foo" as well as your <select name="foo">, you'll get the second (empty) value joined to the first, separated by a comma.
Are there two form elements with the same name? If you have Firebug installed, it's worth taking a look to see if the data is actually being posted with the commas or if it's happening after ASP gets its awful paws on it.