How to enter a half-width alphanumeric text field in monaca

Asked 2 years ago, Updated 2 years ago, 31 views

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.

monaca

2022-09-30 15:50

1 Answers

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.


2022-09-30 15:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.