What pattern to use in a html input field to validate french numbers format? - html

I am looking for the right pattern allowing to validate french numbers (positive integers) in an HTML input.
i.e. thousand separator is a "space".
Ex. of correct values:
1
12 345
1 234 567
Ex. of incorrect:
12x
2x1
1237
I have tried the pattern bellow, but it does not work
<input pattern="([0-9]*[ ]*)*"/>
Thanks for your help

try this -
<input pattern="[0-9 ]+"/>
Note: there is a space before ]
in javascript you can get actual number by replacing all " "(spaces) with "" and converting the string to integer

Related

how do I get an input field in html to ensure the pattern contains a specific country code eg 1472 followed by 3 number and then 4 numbers

I have different sign up pages that load for different countries, and I need the telephone input to be for that specific country, such as on one page it needs to be the country code 1234 followed by any 3 numbers and then any 4 numbers. so I need the pattern for the input in the html form. I am dealing with it on the server side with PHP, but I want to handle it on the client side via the input restriction pattern, as to be more efficient. Im sure its really simple but I cant seem to find a simple solution. thanks for your help
i tried the pattern restriction, i casn get the any 4 number, space, any 3 number, space any 4 numbers. but i could not get the: '1234' specific number, space, any 3 number, space, any 4 numbers.
In this example, the pattern attribute used in the input verifies that the input follows the E.164 standard. The pattern ^+(?:[0-9] ?){6,14}[0-9]$ accepts only strings beginning with + followed by 6-14 numeric characters(optionally separated by spaces) and a numeric character at the end:
<input type="tel" id="phone" name="phone" pattern="^\+(?:[0-9] ?){6,14}[0-9]$" placeholder="+391234567890" oninput="if(this.value.length==3) this.value= this.value + ' '; this.value=this.value.replace(/^(\+39[0-9]{2})([0-9]{4})([0-9]{4})$/,'$1 $2 $3')" value="+39 " minlength="14" maxlength="14" readonly onfocus="this.removeAttribute('readonly')">
The oninput attribute used to format the phone number as the user includes it, in this case to format it as +39 (XXX) XXXX XXXX (Italian prefix, my country for simplicity) In addition, the value attribute is set to +39 so that the user cannot delete the international prefix.

Pure HTML input type text validation using pattern

Recently I tried alot but I still unable to figure how should I able to validation for my text field. I hope I can get some help from here, my questions is I want to validate input text field only accept A-Z a-z 0-9 and space within word. And at least one char or number.
For example, "abc def" , "abc092", "abcdef"
Only in HTML input tag element .
I tried this
but this pattern unable to fullfil my requirements.
the pattern i want to achieve is
1) abc def
2) abcdef
3) abc123
4) a1b2c3 d4e5
5) allow to have empty space within words
the pattern i dont want to accept is
1) empty string
2) no alot of whitespace at the begining or end of the string
3) no bracket and etc special characters
Try
<input type="text" pattern="^\w+([\w ]*\w)*$">
Basically the break down is this:
\w+ - Select a word character ("A-z0-9") one or more times
()* - Select what's in here 0 or more times, which is
[\w ]*\w - Select a word character or space one or more times followed by another word character
No leading or trailing white space allowed. Only word characters allowed and internal spaces.
For some unit tests and breakdown of the regex see: https://regex101.com/r/7UnL9J/1
You can use the Pattern attribute with regex but it is supported only in HTML 5.
Like this " id="username" pattern="[A-Za-z0-9]+"
Check the below link for more information
https://html.com/attributes/input-pattern/#Username_Patterns
Have you tried this?
<input type="text" pattern="[a-zA-Z0-9\s]+">

How to require a specific input length and a 0-9 requirement using pattern attribute?

I need to combine two patterns, however once I put them together using | both of them won't work.
How do you combine such patterns?
This is for an input field (on a form). I want to make the user type 13 characters precisely as well as require numbers only.
I tried:
" pattern="(.){13,13}" maxlength="13" required>
This works. It requires 13 characters but also allows letters.
But once I add the second pattern for requiring numbers only, both patterns won't work.
" pattern="(.){13,13}|[0-9]*" maxlength="13" required>
I expect it to require 13 letters, using numbers only, but it doesn't require neither.
Any help/explanation is greatly appreciated. Thanks in advance!
Use this line:
pattern=".{12,13}[0-9]"
It should only accept exactly 13 numbers, and no letters.

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.

Give tab spacing after first word in text file

Consider I have a .txt file as of the format,
Name: Abc
Id: 123
Age: 12
Address: xyz
I want to convert this file of the form,
Name : Abc
Id : 123
Age : 12
Address : xyz
i.e the Colon after each tile should move 2 or 3 tab spaces. The title will be only a single word and wont have spaces. So the title wont be of the form(Your age:). So i can just read the first word and give tabs after that.
How can i do this? and will doing in perl be simpler or any other language.?
Find the length of the biggest word, add n spaces to it. That's the padding to use when formatting each word.
PHP, for example, has a sprintf() function that you can look at. Various other languages provide formatted output as well.
In PHP, the following format should work - "%-<max>s : %s", where <max> is the length of the biggest word + some padding.
sprintf("%-25s : %s", $key, $value);
- makes the string left aligned.