Pattern attribute HTML not matching regex - html

So I have this line of code :
<form>
<input max="250" required pattern="[A-Za-z0-9 \.\,\!\?\:\[\]\(\)\"\-\+]+"
class="inputBox" type="text" id="comment" name="CommentContent" placeholder="write here">
</form>
but it doesn't seem to match anything at all.
I got it to work for more simple regex but not for this one.
I used a site to validate it and it looks like it's valid.

Change the wrapping quote and don't escape the chars other than the []
<form>
<input max="250" required pattern='[A-Za-z0-9 .,!?:\[\]()"-+]+'
class="inputBox" type="text" id="comment" name="CommentContent" placeholder="write here">
</form>

Related

Is there a pattern to limit the first four numbers in my input box?

The result should be like this, 2018-00130. The first 4 numbers are year, I wanted to limit the year to 2010 up to 2022.
I have tried to use the input type = number but I can't limit the numbers since I need the dash sign.
My pattern for now is just like this, pattern="[^a-zA-Z]*" maxlength = "10".
This is a very basic RegEx and quite simple to implement.
Here's the code:
<form>
<label for="code">Code:</label><br>
<input type="text" id="code" name="code" pattern="20(1[0-9]|2[0-2])-[0-9]{5}" maxlength="10" required>
<input type="submit" value="Submit">
</form>
Try this:
<input type="text" maxlength="4" style="width:50px;"> - <input type="text" maxlength="6">

Regexp with letters and -

I need a regexp with letters and - to use as pattern validate of an input type text,
for example:
<input type="text" name="name" id="name" class="form-control" placeholder="name form" pattern="[A-Za-z-]" required="required">
But it still validate also other characters when i fill and sumbit form.
You can use the following pattern ([A-Za-z\-]+) to check for the whole input:
<input type="text" name="name" id="name" class="form-control" placeholder="name form" pattern="[A-Za-z\-]+" required="required">

Text of input is valid always

I'm going to realize input of text like this:
<input type="text" maxlength="16" required/>
And want to use valid and invalid stations like this:
input:invalid {
background: #fdd;
}
input:valid {
background: #dfd;
}
But when i write any text my input is valid always. I tried use pattern:
pattern=".{16,}"
But that did not solve anything. Where is my mistake?
The input must be valid when length of input is equal to 16.
You're close! Here's how to do it.
Allowing only alphanumerics
<form>
<input id="username" type="text" pattern="[a-zA-Z0-9]{16}" required>
<input id="submit" type="submit" value="create">
</form>
Allowing any character
<form>
<input id="username" type="text" pattern=".{16}" maxlength="16" required>
<input id="submit" type="submit" value="create">
</form>
With jQuery mask() plugin
Here, we just force the delimiter to be part of the input value followed by the number of characters in each group. In this case 4 numbers followed by a space.
$(document).ready(function() {
$('#username').mask('9999 9999 9999 9999');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.0/jquery.mask.min.js"></script>
<form>
<input id="username" type="text" pattern="[0-9]{4} [0-9]{4} [0-9]{4} [0-9]{4}" required>
<input id="submit" type="submit" value="create">
</form>
For more info about regex and patterns, check out Regexr.
In your code, the attribute maxlength="16" does not allow more than 16 characters to be typed in the input box. The regular expression you are using is valid when the input is between 0 and 16 characters. Therefore, you regexp should be:
.{16,16}
And your HTML code:
<input type="text" pattern=".{16,16}" maxlength="16" required/>
You might want to see it working in this fiddle.

Formatting output from mailto:

I'm making a form which collect some data from a person and then use a simple mailto: to put it in their e-mail client like so (example):
<form method="post" action="mailto:email#address.com?subject=Stuff">
<p>Name: <input type="text" name="Name" placeholder="Number"></p>
<p>Address: <input type="text" name="Address" placeholder="Number"></p>
<p>City: <input type="text" name="City" placeholder="Number"></p>
<p>Comment: <input type="text" name="Comment" placeholder="Number"></p>
<p><input type="submit" value="SEND"></p>
</form>
It then comes out like this:
Name=Bob&Address=something&City=more&Comment=elsemore
but what I want is:
Name=Bob
Address=something
City=more
Comment=elsemore
or even better:
Name = Bob
Address = something
City = more
Comment = elsemore
Is it at all possible currently to do this just within HTML? HTML5 and Python is all I know (mostly only the basic parts too). Maybe someone could help me out with the proper code/script on this.
I did find some other posts on this but they are old and don't answer the question.
You need to set the Encryption Type (enctype="text/plain"):
<form method="post" action="mailto:email#address.com?subject=Stuff" enctype="text/plain">
<p>Name: <input type="text" name="Name" placeholder="Number"></p>
<p>Address: <input type="text" name="Address" placeholder="Number"></p>
<p>City: <input type="text" name="City" placeholder="Number"></p>
<p>Comment: <input type="text" name="Comment" placeholder="Number"></p>
<p><input type="submit" value="SEND"></p>
</form>
You could also write some stuff in Javascript and then work with the body parameter. But i wouldn't recommend this.
In most times, it is better to let the webserver handle the email communication.
Asp: http://www.codeproject.com/Tips/371417/Send-Mail-Contact-Form-using-ASP-NET-and-Csharp
Php: http://tangledindesign.com/how-to-create-a-contact-form-using-html5-css3-and-php/

HTML - Make form values disappear, and control the height, and width of text inputs

I am creating a websites, and I have came across a predicament with my coding.
I am writing a 'submit form' and I need it to look like the following example:
Message: (Gives the user to submit a message, or type any comments) And inside the text box, I'd like for it to say 'Type your message here' but when you click within the box, the 'type your message here' disappears. I also would like to be able to control how large this text box is.
Name: Type your first and last name here (I want it to function the same as above)
Email Address: Type your email address here: (Again, function same as above)
This, is the code that I have so far, and I am not sure if it's correct or not, for what I'm trying to do:
<form method="post" action="mailto:youremail#youremail.com" >
<b>Message:</b><br><input type="textbox" value="text_name" onfocus="if (this.value=='Text_name') this.value='';" style="width: 300px;" style="height: 300px;"/><br/>
<b>Name:</b><br><input type="text" name="First and Last" size="30" maxlength="30" /><br />
<b>Email:</b><br><input type="text" name="Email" size="24" maxlength="24" /><br />
<input type="submit" value="Send Email" />
</form>
There are lots of plugins available fir this. But you can use a HTML5 property "placeholder"
<input type="text" placeholder="Enter your name...">
HERE is the demo. Text/hint will diappear as you start typing.
<b>Message:</b><br><input type="textbox" placeholder="Type your message here" style="width: 300px;" style="height: 300px;"/><br/>
<b>Name:</b><br><input type="text" name="First and Last" size="30" maxlength="30" placeholder="Type your first and last name here" /><br />
<b>Email:</b><br><input type="text" name="Email" size="24" maxlength="24" placeholder="Type your email address here"/><br />
<input type="submit" value="Send Email" />
From my understanding this is pretty much a duplicate of: Onclick event to remove default value in a text input field right?
If you are fine with HTML5 then you can use placeholder otherwise you will need to use Javascript that removes the text onblur
I suggest you to use bootstrap css for better styling. Just have a look at this http://getbootstrap.com/css/ . I hope this would be helpful for you
You can define a script and use the below function since it can be used for both onfocus and onblur,
function clearText(field) {
if(field.defaultValue == field.value) {
field.value = “”;
}
else
if(field.value == “”) {
field.value = field.defaultValue;
}
}