HTML Form Pattern Regex - html

I'm trying to have a Reg Exp for the following:
8 characters min
1 uppercase (at least)
1 lowercase (at least)
1 digit (at least)
Excluding: + # &
I have the following but I can't seem to have the right combo of group/sub-group to make them work together:
[^+#&](?=.*\d)(?=.*[a-z])(?=.*[A-Z])).{8,}
I need guidance!

You need to use anchors and place the negated class after your assertions.
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^+#&]{8,}$

Related

RegEx replace only occurrences outside of <h> html tags

I would like to regex replace Plus in the below text, but only when it's not wrapped in a header tag:
<h4 class="Somethingsomething" id="something">Plus plan</h4>The <b>Plus</b> plan starts at $14 per person per month and comes with everything from Basic.
In the above I would like to replace the second "Plus" but not the first.
My regex attempt so far is:
(?!<h\d*>)\bPlus\b(?!<\\h>)
Meaning:
Do not capture the following if in a <h + 1 digit and 0 or more characters and end an closing <\h>
Capture only if the group "Plus" is surrounded by spaces or white space
However - this captures both occurrences. Can someone point out my mistake and correct this?
I want to use this in VBA but should be a general regex question, as far as I understand.
Somewhat related but not addressing my problem in regex
Not relevant, as not RegEx
You can use
\bPlus\b(?![^>]*<\/h\d+>)
See the regex demo. To use the match inside the replacement pattern, use the $& backreference in your VBA code.
Details:
\bPlus\b - a whole word Plus
(?![^>]*<\/h\d+>) - a negative lookahead that fails the match if, immediately to the right of the current location, there are
[^>]* - zero or more chars other than >
<\/h - </h string
\d+ - one or more digits
> - a > char.

Can you create a pattern for HTML input fields with a minimum number of letters of a certain type?

I want to create a pattern for an HTML input field that needs to have at least 10 numbers in it and may also have spaces and a plus sign on top of that, but it's not required.
It's important that numbers and spaces can be mixed though. Also, the whole field can only have 17 characters all in all.
I'm not sure if it's even possible. I started doing something like that:
pattern="[0-9+\s]{10,17}*"
But like this, it's not guaranteed that there are at least 10 numbers.
Thanks in advance! Hope the question doesn't exist already, I looked but couldn't find it.
You can use
pattern="(?:[+\s]*\d){10,17}[+\s]*"
The regex matches
(?:[+\s]*\d){10,17} - ten to seveteen occurrences of zero or more + or whitespaces and then a digit
[+\s]* - zero or more + or whitespaces.
Note the pattern is anchored by default (it is wrapped with ^(?: and )$), so nothing else is allowed.

HTML5 pattern need help making a specific pattern for an input

Im trying to make a pattern that will allow input such as SB 0023467-01 or ST 0023467-02
<input type="text" name="surat_beranak" pattern="[S]+[B\s]+[0-9]{7}+[-]+[0]+[^0-1]"
oninvalid="this.setCustomValidity('Format SB 0029384-01')"value="<?= $surat_beranak;?>"
class="form-control" placeholder="Enter Surat Beranak Number" required>
This is my current input pattern, but it's not working as intended. I need help where the pattern will allow only S as the first letter, then B or T as the second letter, then have a space after. Then there will be 7 numeric digits followed by a dash and a number, 0 then 1 or 2
You're using + between every character, which allows a character to be repeated many times. It is the equivalent of using {1,}. [0-9]{7}+ is invalid.
You're using square brackets, allowing different characters to be used in a same place. A good place to use these would be for the beginning: S[BT] would allow SB or ST. There is no need to wrap single characters with these brackets.
Your current pattern ends with [^0-1], which means "every character except 0 and 1". It goes against your goal of having "01" or "02" at the end.
Your pattern, in HTML, would be S[BT] [0-9]{7}-0[12]. If you're using this pattern anywhere else, you should wrap it between ^ and $, in order to only allow the input you want, and nothing else.
In the future, please use regex testers in order to test your pattern. Example with the working pattern and a few input examples.

None of the REGEX I've tried work in an HTML Input Pattern

I am trying to make an HTML input to only be able to receive float numbers like: x.123 x,123 x.123456 x,123456
Where x can have one or 2 digits: x or xx.
Basically I would like to know how to make a pattern that only accepts those kind of numbers.
Reading around the WEB I found two patterns that should've matched my needs, but they do not work.
^[+-]?([0-9]*[.])?[0-9]+$
^(?=.)(\d{1,2}(,\d{3,6})*)?(\.\d+)?$
These were found, I don't understand how this works.
Googling Regex I found a lot of tools that work for,on or with (I don't have any idea) JavaScript, PHP, RUBY, PCRE.
I don't understand what coding language they use or how. And after digging into it more I found myself even more lost and having more questions.
Is there any reverse tool that actually makes the regex ?
I found this http://buildregex.com/ but I don't know how it works...
This is me trying to make my pattern...
/(?:(?:(?:(?:(?:(?:)|(?:(?:22\.123))|(?:(?:2\.123))|(?:(?:22\.123))|(?:)|(?:)|(?:))))))/
EDIT:
This is is the input:
<input id="text-input" type="text" inputmode="numeric" pattern="/^[\d]{1,2}[.,][\d]{3,6}$/"
oninvalid="this.setCustomValidity('Please enter a number with 3-6 decimals')"
onchange="try{setCustomValidity('')}catch(e){}"
oninput="setCustomValidity(' ')"
>
You can use pattern="^\d{1,2}[.,]\d{3,6}$"
^\d{1,2} starting with 1 to 2 digit(s)
[.,] followed by either a comma, either a dot
\d{3,6}$ ending by 3 to 6 digits
There're no needs for delimiters and anchors, use:
pattern="\d{1,2}[.,]\d{3,6}"
^\d{1,2}[\.]\d{3,6}$ ,
^d{1,2} means: max 2 digit start with.
[\.] means : having . in middle.
d{3,6} means min 3 and max 6 digit of decimal points at the end.

<input type=number> and format using one decimal place in Chrome

I am using <input type=number> where I place values using Javascript. I'd like to format these numbers to have always one decimal. Chrome stubbornly strips out of trailing zero from the numbers if they have any e.g. 1.0 -> 1.
Apparently I should set pattern attribute of the control. However I am not sure what kind of values Chrome accepts here and what would be the correct pattern for formatting numbers.
pattern is used to specify a regular expression that any value the user supplies should match. Something like pattern='[0-9]+\.[0-9]' should specify 1 or more digits, a decimal, then 1 digit. You might also want to set the step size to 0.1 (step=0.1) to force only 1 decimal. I don't know if chrome will respect the pattern and size attributes or not, but that is how to specify them.