Salut
Vezi exemplele urmatoare; le poti adapta la ce iti trebuie.
Cu jQuery:
Cod: SelectaĊ£i tot
<form action="" method="post" id="idform">
<input type="text" name="nume" id="idinput" />
<input type="submit" value="Click" />
</form>
<script type="text/javascript"><!--
// marplo.net / www.coursesweb.net
var regx_chr = /^([A-Za-z\[\]\?\|\.]+)$/; // RegExp cu caracterele permise
// cand formularul e trimis, preia cu jQuery si verifica daca in #idinput sunt caracterele permise
$(document).ready(function() {
$('#idform').submit(function() {
var inpbox = $('#idinput').val();
if(inpbox.search(regx_chr) == -1) {
alert('Adaugti cel putin un caracter.\n Doar litere, [, ], |, ?, .');
return false;
}
});
});
--></script>
- Fara jQuery:
Cod: SelectaĊ£i tot
<form action="" method="post" id="idform">
<input type="text" name="nume" id="idinput" />
<input type="submit" value="Click" />
</form>
<script type="text/javascript"><!--
// marplo.net / www.coursesweb.net
var regx_chr = /^([A-Za-z\[\]\?\|\.]+)$/; // RegExp cu caracterele permise
// cand formularul e trimis, preia si verifica daca in #idinput sunt caracterele permise
function checkForm() {
var inpbox = document.getElementById('idinput').value;
if(inpbox.search(regx_chr) == -1) {
alert('Adaugti cel putin un caracter.\n Doar litere, [, ], |, ?, .');
return false;
}
}
// inregistreaza eveniment sa apeleze checkForm() cand formularul "idform" e trimis
document.getElementById('idform').onsubmit = checkForm;
--></script>