removing char in string after space - html

I'm having problem with that java framework seems to remove the content of a string after a space character.
code example
<input type="text" name="txtName" size="25" value=<%=Name%>>
If Name is equal to "This is my name" the input text only show "This".
I'm guessing this is to avoid xss problems but I need to be able to use strings that contain space so how do I get around this? (i'm using tomcat)

You need to add quotes around the value of your value attribute.
This is always the case in HTML when attribute values contain spaces.
(ie it has nothing to do with Java)
It should look like this:
<input type="text" name="txtName" size="25" value="<%= Name %>">

This will do... value="<%=Name%>"
<input type="text" name="txtName" size="25" value="<%=Name%>">

Related

Pattern attribute not working as expected?

So I'm trying to make a form for my assignment, and I am using the pattern attribute in html so only certain characters are required to be typed on the text box. But for some reason, the form is saying using that I'm using an incorrect format even though I made my pattern attribute that way.
Here's an example of the code and a picture of the problem.
<form>
<label for="mnumber">Mobile Number:</label>
<input type="text" required id="mnumber" pattern="[0-9]"><br><br>
<input type="submit" value="submit">
</form>
You did write:
pattern="[0-9]"
You are asking for only one number. You just forget to add '+' to accept more than one number. I guess what you are searching for is this:
pattern="[0-9]+"
pattern="[0-9]"
allows for only a single number character to validate (and be submitted). If you want to allow more than one character, here's your options:
One or more numbers:
pattern="[0-9]+"
Zero or more numbers:
pattern="[0-9]*"
One to three numbers:
pattern="[0-9]{1,3}"
you just need to change type="text" to type="number"

HTML form - input validation with Alphanumeric with symbols ()._-‘ only

I want to validate below input with Alphanumeric and ()._-‘ symbol only.
<input type="text" name="companyName" value="" pattern="[A-Za-z0-9()._-‘]+" title="Alphanumeric with symbols ()._-‘ only" required> </p>
But, when I try the input, only ._‘ can be used, ()- are not working.
You need to escape those characters. They have significance in RegEx and aren't treated as part of the expression. Try the following: [A-Za-z0-9\(\)._\-‘]+
Works fine for me, with the exception of the '-' which probably needs to be first:
[-A-Za-z0-9()._‘]
Try the code below. I don't know why, but the order for the pattern attribute matters.
<form>
<input type="text" name="companyName" value="" pattern="[A-Za-z0-9()_.'-]+" title="Alphanumeric with symbols ()._-‘ only" required>
<input type="submit">
</form>

HTML form validation with the “pattern” attribute

I am trying to come up with a valid pattern for an HTML form. I would like to allow *#student.*.edu.vn
This is my code:
<input
type="text"
name="mail"
pattern="([a-z]|[0-9])+(#{1})+(student)+(.)+[a-z]+(.edu.vn)"
/>
It does not work as I would like. What I am doing wrong?
The pattern (regular expression) is slightly wrong as you haven't escaped all your special characters such as the . and have some unnecessary parts within it. Try using the following slightly modified pattern instead:
([a-z]|[0-9])+#student\.[a-z]+\.edu\.vn
<form>
<input type="text" name="mail" pattern="([a-z]|[0-9])+#student\.[a-z]+\.edu\.vn" />
<input type="submit">
</form>
Note: Make sure that you also do validation on the server-side as anyone entering values into a form can remove the pattern to bypass this check.
I came up with this solution which is slightly more easy to read and is less strict (which is a good thing because e-mail addresses can contain a lot more characters than just lowercase alpha-numeric ones. Don't forget to do proper validation on the backend using an e-mail validator.
<form>
<input
type="text"
name="mail"
pattern=".+#student\..+\.edu.vn"
/>
<input type="submit">
</form>

HTML - special input email pattern for more options

I need a specific pattern for email input. There should be 2 options:
john#doe.com
john#doe.com:anything
I need to fit in the ":anything" and make more possibilities after ":".
At the moment I'm using this but it does only validation for normal email:
<input class="input-fields" id="formUsername" name="username" type="text" pattern="[a-z0-9._%+-]+#[a-z0-9.-]+\.[a-z]{2,3}" autofocus required/>
I tried many combinations but I just can figure out the right one.
You could add ':?\w*' to Your regex, so it would look like
[a-z0-9._%+-]+#[a-z0-9.-]+.[a-z]{2,3}:?\w*
can't you just add more textboxes(only for the extra part fiddle here)?
Optional(only for blahblahblah):
<input class="optional-fields" title="optional" id="designation" type="text" pattern="[a-z]{5,}">

Validating cell no using regular expression

I am trying to validate cell no using html. I've write the following regular expression but its not working. Can anybody please help me?
<input required="required" name="txtcellno" id="txtcellno" type="text" value="" pattern="/^+[9][2][0-9]{1,10}$/" placeholder="+92xxxxxxxxxx" />
+ has special meaning, and should be escaped (\+).
Input patterns must match the whole string, so ^ and $ are unnecessary.
Input patterns must not be wrapped in /.../
Given all that, and simplifying [9][2] to 92:
<input required="required" name="txtcellno" id="txtcellno" type="text"
value=""
pattern="\+92[0-9]{1,10}"
placeholder="+92xxxxxxxxxx" />
Example: http://codepen.io/paulroub/pen/jELiI