# Pascal | Validation String



## bhstr99 (Apr 10, 2010)

Hi im currently trying to validate a string so no numbers can be entered, only letters.


```
Procedure NewUser (Day,TestDate:Integer; Number:String);
Var name : array [1..20] of Integer; validate : array [1..20] of Integer;
    InfoDisplayYN, InfoSaveYN : String; Confirm : Boolean;
  begin
     Clrscr;
    With User do
    Begin
    repeat
      repeat
      Clrscr;
      DisplayDate;
    Title;
      GOTOXY(18,10);
      Write ('Please enter your name in lower case letters: ');
      Readln(Firstname);
  Val (FirstName[1], Name[1], Validate[1]);
  Val (FirstName[2], Name[2], Validate[2]) ;
  Val (FirstName[3], Name[3], Validate[3])  ;
  Val (FirstName[4], Name[4], Validate[4])   ;
  Val (FirstName[5], Name[5], Validate[5])    ;
  Val (FirstName[6], Name[6], Validate[6])     ;
  Val (FirstName[7], Name[7], Validate[7])      ;
  Val (FirstName[8], Name[8], Validate[8])       ;
  Val (FirstName[2], Name[2], Validate[9])        ;
  Val (FirstName[10], Name[10], Validate[10])      ;
  Val (FirstName[11], Name[11], Validate[11])       ;
  Val (FirstName[12], Name[12], Validate[12])        ;
  Val (FirstName[13], Name[13], Validate[13])         ;
  Val (FirstName[14], Name[14], Validate[14])          ;
  Val (FirstName[15], Name[15], Validate[15])           ;
  Val (FirstName[16], Name[16], Validate[16])            ;
  Val (FirstName[17], Name[17], Validate[17])             ;
  Val (FirstName[18], Name[18], Validate[18])              ;
  Val (FirstName[19], Name[19], Validate[19])               ;
  Val (FirstName[20], Name[20], Validate[20])                ;


    Until  (Validate[1] <> 0) AND (Validate[2] <> 0) and (Validate[3] <> 0) and (Validate[4] <> 0)
       and (Validate[5] <> 0) and (Validate[6] <> 0) and (Validate[7] <> 0) and (Validate[8] <> 0)
       and (Validate[9] <> 0) and (Validate[10]<> 0) and (Validate[11]<> 0) and (Validate[12]<> 0)
       and (Validate[13]<> 0) and (Validate[14]<> 0) and (Validate[15]<> 0) and (Validate[16]<> 0)
       and (Validate[17]<> 0) and (Validate[18]<> 0) and (Validate[19]<> 0) and (Validate[20]<> 0);

       if   (Validate[1] <> 0) AND (Validate[2] <> 0) and (Validate[3] <> 0) and (Validate[4] <> 0)
       and (Validate[5] <> 0) and (Validate[6] <> 0) and (Validate[7] <> 0) and (Validate[8] <> 0)
       and (Validate[9] <> 0) and (Validate[10]<> 0) and (Validate[11]<> 0) and (Validate[12]<> 0)
       and (Validate[13]<> 0) and (Validate[14]<> 0) and (Validate[15]<> 0) and (Validate[16]<> 0)
       and (Validate[17]<> 0) and (Validate[18]<> 0) and (Validate[19]<> 0) and (Validate[20]<> 0)
        then
          begin
          Confirm := True;
          end
          else
          begin
          GOTOXY(10,12);
          Write ('You are only allowed to enter letters ');
          Writeln ('Press enter to try again... ');
          Readln;
        end;
        Until (Confirm = True) and (Firstname <> '') and (Firstname <> ' ') and (Firstname <> '  ');
end.
```
It validates but the problem is the ''You are only allowed to enter letters'' doesn't come up when it validates that numbers have been entered. 
:4-dontkno


----------



## Ninjaboi (Dec 27, 2010)

Hi bhstr99.

You may be interested in looking at these two links:

Here.
Here.


----------



## AlbertMC2 (Jul 15, 2010)

Hi

I have not tested the procedure but it would seem this section:

```
repeat 
   Clrscr; 
   DisplayDate; 
   Title; 
   GOTOXY(18,10); 
   Write ('Please enter your name in lower case letters: '); 
   Readln(Firstname); 
   Val (FirstName[1], Name[1], Validate[1]); 
   Val (FirstName[2], Name[2], Validate[2]) ; 
   Val (FirstName[3], Name[3], Validate[3]) ; 
   Val (FirstName[4], Name[4], Validate[4]) ; 
   Val (FirstName[5], Name[5], Validate[5]) ; 
   Val (FirstName[6], Name[6], Validate[6]) ; 
   Val (FirstName[7], Name[7], Validate[7]) ; 
   Val (FirstName[8], Name[8], Validate[8]) ; 
   Val (FirstName[2], Name[2], Validate[9]) ; 
   Val (FirstName[10], Name[10], Validate[10]) ; 
   Val (FirstName[11], Name[11], Validate[11]) ; 
   Val (FirstName[12], Name[12], Validate[12]) ; 
   Val (FirstName[13], Name[13], Validate[13]) ; 
   Val (FirstName[14], Name[14], Validate[14]) ; 
   Val (FirstName[15], Name[15], Validate[15]) ; 
   Val (FirstName[16], Name[16], Validate[16]) ; 
   Val (FirstName[17], Name[17], Validate[17]) ; 
   Val (FirstName[18], Name[18], Validate[18]) ; 
   Val (FirstName[19], Name[19], Validate[19]) ; 
   Val (FirstName[20], Name[20], Validate[20]) ; 
Until (Validate[1] <> 0) AND (Validate[2] <> 0) and (Validate[3] <> 0) and 
       (Validate[4] <> 0) and (Validate[5] <> 0) and (Validate[6] <> 0) and 
       (Validate[7] <> 0) and (Validate[8] <> 0) and (Validate[9] <> 0) and 
       (Validate[10]<> 0) and (Validate[11]<> 0) and (Validate[12]<> 0) and 
       (Validate[13]<> 0) and (Validate[14]<> 0) and (Validate[15]<> 0) and 
       (Validate[16]<> 0) and (Validate[17]<> 0) and (Validate[18]<> 0) and 
       (Validate[19]<> 0) and (Validate[20]<> 0);
```
repeats until the input is valid (ie. all characters and no integers)

Therefore when (and if) the repeat finally exits, because the input is a string of characters, the next section is always true:

```
if (Validate[1] <> 0) AND (Validate[2] <> 0) and (Validate[3] <> 0) and 
   (Validate[4] <> 0) and (Validate[5] <> 0) and (Validate[6] <> 0) and 
   (Validate[7] <> 0) and (Validate[8] <> 0) and (Validate[9] <> 0) and 
   (Validate[10]<> 0) and (Validate[11]<> 0) and (Validate[12]<> 0) and 
   (Validate[13]<> 0) and (Validate[14]<> 0) and (Validate[15]<> 0) and 
   (Validate[16]<> 0) and (Validate[17]<> 0) and (Validate[18]<> 0) and 
   (Validate[19]<> 0) and (Validate[20]<> 0) then 
   begin 
       Confirm := True; 
    end 
    else 
    begin 
        GOTOXY(10,12); 
        Write ('You are only allowed to enter letters '); 
        Writeln ('Press enter to try again... '); 
         Readln; 
      end;
```
so the first section of the if statement always runs. But the second section (the else) never runs.


----------

