# การตรวจสอบความถูกต้องของข้อมูล (Symfony) > Constraints, custom validator, validation groups, การตรวจสอบ Entity, การตรวจสอบ DTO - 18 คำถามสัมภาษณ์ - Junior - [คำถามสัมภาษณ์: Symfony](https://sharpskill.dev/th/technologies/symfony/interview-questions.md) ## 1. บทบาทหลักของ component Validator ของ Symfony คืออะไร? **คำตอบ** component Validator ของ Symfony ตรวจสอบความถูกต้องของข้อมูลตามกฎที่กำหนดไว้ที่เรียกว่า constraints สามารถตรวจสอบอ็อบเจกต์ ค่าสเกลาร์ และอาร์เรย์ได้ โดยจะคืนค่ารายการ violation หากไม่เป็นไปตามกฎ component นี้ถูกผสานรวมกับฟอร์ม แต่ก็สามารถใช้งานแบบแยกอิสระได้เช่นกัน ## 2. ควรใช้ constraint ใดเพื่อตรวจสอบว่า field ไม่ว่างเปล่าหรือเป็น null? **คำตอบ** constraint NotBlank ตรวจสอบว่าค่าหนึ่งไม่ว่างเปล่า (สตริงว่าง, null หรืออาร์เรย์ว่าง) ซึ่งต่างจาก NotNull ที่ยอมรับสตริงว่าง NotBlank ถูกใช้บ่อยที่สุดสำหรับ field ฟอร์มที่จำเป็น เพราะมันยังปฏิเสธสตริงที่มีเฉพาะช่องว่างอีกด้วย ## 3. จะใช้ validation constraint กับ property ของ entity โดยใช้ attributes ของ PHP 8 ได้อย่างไร? **คำตอบ** ตั้งแต่ PHP 8 เป็นต้นมา validation constraint จะถูกนำไปใช้ผ่าน attributes ที่อยู่เหนือ property โดยตรง ไวยากรณ์ใช้คำนำหน้า Assert ร่วมกับ namespace Symfony\Component\Validator\Constraints แนวทางนี้กระชับกว่าการใช้ annotation แบบ DocBlock และได้ประโยชน์จากการรองรับแบบ native ของ PHP ## มีอีก 15 คำถาม - constraint ใดที่ตรวจสอบว่าสตริงตรงกับรูปแบบอีเมลที่ถูกต้อง? - จะตรวจสอบความยาวของสตริงด้วยค่าต่ำสุดและสูงสุดได้อย่างไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Symfony อื่นๆ - [PHP สมัยใหม่ (8.1+)](https://sharpskill.dev/th/technologies/symfony/interview-questions/php-modern-features.md): 20 คำถาม, Junior - [พื้นฐาน Symfony](https://sharpskill.dev/th/technologies/symfony/interview-questions/symfony-basics.md): 25 คำถาม, Junior - [Routing & Controllers](https://sharpskill.dev/th/technologies/symfony/interview-questions/routing-controllers.md): 20 คำถาม, Junior - [Twig & Templates](https://sharpskill.dev/th/technologies/symfony/interview-questions/twig-templates.md): 20 คำถาม, Junior - [พื้นฐาน Doctrine ORM](https://sharpskill.dev/th/technologies/symfony/interview-questions/doctrine-orm-basics.md): 25 คำถาม, Junior - [ฟอร์ม Symfony](https://sharpskill.dev/th/technologies/symfony/interview-questions/forms.md): 22 คำถาม, Junior - [Dependency Injection & Services](https://sharpskill.dev/th/technologies/symfony/interview-questions/dependency-injection.md): 24 คำถาม, Mid-Level - [Security & Authentication](https://sharpskill.dev/th/technologies/symfony/interview-questions/security-authentication.md): 26 คำถาม, Mid-Level - [Doctrine ขั้นสูง](https://sharpskill.dev/th/technologies/symfony/interview-questions/doctrine-advanced.md): 24 คำถาม, Mid-Level - [API Platform](https://sharpskill.dev/th/technologies/symfony/interview-questions/api-platform.md): 22 คำถาม, Mid-Level - [Serializer Component](https://sharpskill.dev/th/technologies/symfony/interview-questions/serializer.md): 20 คำถาม, Mid-Level - [Events & Event Subscribers](https://sharpskill.dev/th/technologies/symfony/interview-questions/events-subscribers.md): 20 คำถาม, Mid-Level - [Console & Commands](https://sharpskill.dev/th/technologies/symfony/interview-questions/console-commands.md): 18 คำถาม, Mid-Level - [Messenger Component](https://sharpskill.dev/th/technologies/symfony/interview-questions/messenger.md): 22 คำถาม, Mid-Level - [HTTP Client](https://sharpskill.dev/th/technologies/symfony/interview-questions/http-client.md): 18 คำถาม, Mid-Level - [Cache & ประสิทธิภาพ](https://sharpskill.dev/th/technologies/symfony/interview-questions/cache.md): 20 คำถาม, Mid-Level - [Workflow Component](https://sharpskill.dev/th/technologies/symfony/interview-questions/workflow.md): 18 คำถาม, Mid-Level - [Testing Symfony](https://sharpskill.dev/th/technologies/symfony/interview-questions/testing.md): 22 คำถาม, Mid-Level - [Mailer Component](https://sharpskill.dev/th/technologies/symfony/interview-questions/mailer.md): 16 คำถาม, Mid-Level - [การแปลและ i18n](https://sharpskill.dev/th/technologies/symfony/interview-questions/translations.md): 16 คำถาม, Mid-Level - [EasyAdmin Bundle](https://sharpskill.dev/th/technologies/symfony/interview-questions/easyadmin.md): 18 คำถาม, Mid-Level - [สถาปัตยกรรม Symfony](https://sharpskill.dev/th/technologies/symfony/interview-questions/architecture-patterns.md): 24 คำถาม, Senior - [ประสิทธิภาพและการเพิ่มประสิทธิภาพ](https://sharpskill.dev/th/technologies/symfony/interview-questions/performance-optimization.md): 22 คำถาม, Senior - [ความปลอดภัยขั้นสูง](https://sharpskill.dev/th/technologies/symfony/interview-questions/security-advanced.md): 22 คำถาม, Senior - [Custom Bundles](https://sharpskill.dev/th/technologies/symfony/interview-questions/custom-bundles.md): 20 คำถาม, Senior - [Microservices ด้วย Symfony](https://sharpskill.dev/th/technologies/symfony/interview-questions/microservices.md): 22 คำถาม, Senior - [Real-time & WebSockets](https://sharpskill.dev/th/technologies/symfony/interview-questions/real-time.md): 18 คำถาม, Senior - [Deployment & DevOps](https://sharpskill.dev/th/technologies/symfony/interview-questions/deployment-devops.md): 20 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/symfony/interview-questions/validation