I am trying to implement a system that when the user enters numeric data in a textarea, these will be separated by a comma every two values. As an example, another part of the program consists of pressing a button to generate a random number between -10 and 99 and this number shows them in a textArea. This I get well with this code:
function tipoRadio()
{
var medidas = elementoID("medidas");//capturo elemento
if (this.id === "medidas_manual")//si el elemento tiene este id
{
medidas.value = "";//le vacio
medidas.disabled = "";//le habilito para poder escribir en el
}
if (this.id === "medidas_aleatorio")//si tenemos este id
{
var aleatorios = generarValoresAleatorios();//obtengo array aleatorios
var ale = "";
for (var i = 0; i < aleatorios.length; i++) {
ale += aleatorios[i] + ", ";//Los voy añadiendo a una variable con
comas en medio
}
medidas.value = ale;//muestro la variable
medidas.disabled = "false";
}
}
function generarValoresAleatorios()//Funciona que me genera el array
aleatorios
{
var arrayAleatorios = new Array();
for (var i = 0; i < 30; i++) {
arrayAleatorios.push(aleatoriosEntreMinimoMaximo(-10, 99));
}
return arrayAleatorios;
}
This result I want to get but the user will enter the data manually. Only number in format two digits 01, 44, 08 or is also valid -9, -6 for negative numbers. The maximum number of digits is two. The user is not obliged to write the commas .... Summing up, the user enters:
- 00 ------------ well
- 80 ------------ good
- -5 ------------ good
- 06 ------------ well
- 6 ------------ badly missing another digit
- 7- ------------ bad the least can not go behind just in front (negative number)
I do not know if I explain. I'm editing the question as I go polishing the problem thanks to the comments. Greetings