Question : How do I change this JavaScript so it returns only one correct input and not two as it does now?

How do I change this JavaScript so it returns only one correct input and not two as it does now?

Now, the JavaScript accepts inputs of digits ddd dd and dddd dd (I want it to only accept ddd dd).
I can't get it, because /\d{3}\s\d{2}$/;  should have limited first to only three digits, then space then only two digits and end of row with dollar sign. But it doesn't, it accepts two input forms.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var korrektpostnummer=/\d{3}\s\d{2}$/;  
    function Postnummer(formular) 
    {
    var pNum=document.formular.postnummer.value;
    if (korrektpostnummer.test(pNum)) 
		 	 {
    alert ("Postnumret giltigt");
    return true; 
       }
    else 
		   {
    alert ("Postnumret ogiltigt");
    return false;
       }
    }

Answer : How do I change this JavaScript so it returns only one correct input and not two as it does now?

I would personally not have the alert in the test and not alert when ok
e.g.


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
var korrektpostnummer=/^\d{3}\s\d{2}$/; 

function validate(formular) {
  var pNum=formular.postnummer.value;
  if (!korrektpostnummer.test(pNum)) {
    alert ("Postnumret ogiltigt");
    formular.postnummer.focus();
    return false;
  }

  if (some other test) { // here we can test other fields 
    alert ("some other error");
    formular.someOtherField.focus();
    return false;
  }
  
  return true; // allow submit

}


<form onsubmit="return validate(this)">
Random Solutions  
 
programming4us programming4us