I am developing an application for Android with monaca.
I want to limit the text field on the screen to half-width alphanumeric characters, but it doesn't work properly.
I tried specifying type="url" and type="email" in the input tag, but it is not a half-width alphanumeric character.
Please let me know if anyone knows a good way.
Limiting input values is a difficult problem.
input
seems to have been given type="url"
type="email"
, but
On Android, these are all synonymous with type="text"
.
There are other pattern attributes
, but
This is to limit the input value with regular expressions.
However, this attribute does not guarantee input values.
(*It's better than not putting it in, so I think you can put it in.)
Therefore, I think it is most certain that we check the string after entering it.
/**
* check input and limit to half-width alphanumeric characters
* @paramere Element
**/
function check_val(ele){
// Original string
var origin =ele.value;
// Array one character at a time
var strs = origin.split(');
// String after check
var checks=';
// Check one character at a time and add if escapes are not responsive
for (varn = 0, len = strs.length; n<len;n++) {
varwork=escape(strs[n]);
if(1==work.length) {checks+=work;}
}
// Re-subscribe results to input
ele.value=checks;
}
<input type="url" pattern="^[0-9A-Za-z]+$"value="onchange="check_val(this);"/>
Full-width samples can be deleted, but
It is also possible to modify the above to change the full-width alphanumeric characters to half-width.
Try various trials and errors.
© 2024 OneMinuteCode. All rights reserved.