1

I have the following textarea value:

<textarea name="field" id="field" rows="5" class="form-control"
placeholder="Describe your guests" required="">
Checkin(dd.mm.yyyy): 29.07.2015
Checkout(dd.mm.yyyy): 30.07.2015
Last Name: Johnson
First Name: James
Date of birth(dd.mm.yyyy): 12.12.1995
Country Code: ISR
Passport Number: 150150150
Visa: Type D 1520 or Visa:
</textarea>

I want to vaildate the Checkin information, Checkin(dd.mm.yyyy): has to be dd.mm.yyy otherwise throw an error, Country Code: has to be 3 digits all uppercase for example? I know it is much easier to vaildate each field individually. I need to vaildate pieces inside the textarea.. preferably via jQuery. Any suggestions?

Ilanus
  • 5,397
  • 4
  • 10
  • 33
  • What will you handle if user misedited the Labels, like `Checkin(dd.mm.yyyy): 29.07.2015` becomes `Cci(mm.yyyy): 29.07.2015`? – fuyushimoya Aug 03 '15 at 14:10
  • I wanted to somehow hold this form and make it unchangeable via jQuery too. so if someone copy information it will "auto fix" it... – Ilanus Aug 03 '15 at 14:11
  • 2
    I'd suggest you use some divs and add `contenteditable` attr to them, then use `css` to decorate them as a large `textarea`. If you don't want the inputs. – fuyushimoya Aug 03 '15 at 14:12
  • @fuyushimoya so the user will have to fill-up each div? – Ilanus Aug 03 '15 at 14:15
  • Does the `textarea`'s values no need? You still can set text as initial value to them. – fuyushimoya Aug 03 '15 at 14:16
  • @fuyushimoya this might be something that can help me, is there any example live? Thanks – Ilanus Aug 03 '15 at 14:23
  • [jsfiddle](https://jsfiddle.net/d32o1qtg/3/) is something like this you're looking for? – fuyushimoya Aug 03 '15 at 14:42
  • @fuyushimoya this is sort of it. Is it possible to copy-paste, the whole content, and the values will be autofilled? I remember I saw it somewhere can't find it.. Same way Codeacademy vaildate thier "textareas" code fields.. – Ilanus Aug 03 '15 at 14:52
  • I've answer a question about copy&paste [here] (http://stackoverflow.com/a/30942717/1737627), you can see how to get text from clipboard and insert to each `input`, should share some idea, however, I'm not good at validating, can't help more. – fuyushimoya Aug 03 '15 at 15:03

2 Answers2

0

If you are planning on using bootstrap or similar templates CSS, you could easily use their validation tools (much cleaner and easier). However, with simple HTML I like to use http://jqueryvalidation.org/ This website provides great tutorials and videos as well.

Tigerjz32
  • 3,656
  • 4
  • 23
  • 33
-1

How about using javascript regular expressions?