Jump to content
php.lv forumi
  • 0

JS money validate


NBS

Question

Sveiki, kļūdas nav, vienkārši nesapratu kāpēc nestrādā kā vajadzētu RegExp, jo tas man piekasās, pat tad, ja viss pareizi savadīts inputos.

Šos inputus, ko man vajag pārbaudīt es izvadu ar JS palīdzību.

Lai saprastu kā iegūstu iekšs html inputus:

 

.....
newTd.innerHTML = 'input type="text" id="cost'+ lastId +'" name="cost'+ lastId +'" size="4" />';
.....

Validācijas kods:

function validate()
{
var reg = new RegExp('^[+]?\d+(\.\d{1,2})?$');
for (var i = 1; i < document.getElementById('count').value; i++)
{
	if (!reg.test(document.getElementById('cost'+ i).value))
	{
		alert("Nepareizi ievadīta pakalpojuma summa!");
		return false;
	}
}
return true;
}

 

Paldies, savlaicīgi.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

document.getElementById('count').value getbyID kuku ID var but tikai viens un tas pats nav atrodams

Link to comment
Share on other sites

  • 0
document.getElementById('count').value getbyID kuku ID var but tikai viens un tas pats nav atrodams

 

Man šis count ir viens un aizpildīts ar skaitli, kas veic ciklu.

Pārējie ID tiek pieskaitīti klāt ('cost'+ i).

Tie neatkārtojas.

Edited by NBS
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...